Loop with row and column difference (multiplication)
Mostra commenti meno recenti
I would like to know how I do a loop multiplying Q1 with O3 (result in Q3). Then multiply Q3 with O4 and so on for each column.

I tried to explain with other software to facilitate understanding. Thank you for your help.
3 Commenti
Jacqueline Rigatto
il 10 Nov 2020
David Hill
il 10 Nov 2020
Did you look at my answer? First load your file and look at the data to see how it was loaded (how it is named). It would help if you attached your data file.
load('yourfile');
Jacqueline Rigatto
il 10 Nov 2020
Risposte (2)
David Hill
il 10 Nov 2020
Modificato: David Hill
il 10 Nov 2020
I assume your arrays when imported will start at 1. Looks like you just want cumprod() of O times initial Q.
Q(2:end)=Q(1)*cumprod(O);
6 Commenti
David Hill
il 10 Nov 2020
clear all; clc; close all
alpha=0.008;
gamma=3.3;
g=9.8;
delta_1=0.07;
delta_2=0.09; % if f>fp
Tp=[2 8 16];
freq_p=1./Tp;
i_freq=1:69;
f1=0.03093;
c=1.1;
for i = 1:length(i_freq)
fi=f1.*c.^(i_freq-1);
end
freq_fi=fi;
nrows = length(freq_fi);
ncols = length(freq_p);
E = ones(nrows,ncols);
fc = 0.4054; % [rad/s]
for i = 1:nrows
for j = 1:ncols
f = freq_fi(i);
fp = freq_p(j);
if f<fc
if f<=fp
E(i,j) = (alpha*(g^2)*((2*pi)^(-4))*(f^(-5)))*exp((-5/4)*((f/fp)^(-4)))*gamma*exp((-1/2)*((f-fp)/(delta_1*fp))^2);
else
E(i,j) = (alpha*(g^2)*((2*pi)^(-4))*(f^(-5)))*exp((-5/4)*((f/fp)^(-4)))*gamma*exp((-1/2)*((f-fp)/(delta_2*fp))^2);
end
elseif f>fc
if f<=fp
E(i,j) = (fc/f)^5*(alpha*(g^2)*((2*pi)^(-4))*(f^(-5)))*exp((-5/4)*((f/fp)^(-4)))*gamma*exp((-1/2)*((f-fp)/(delta_1*fp))^2);
else
E(i,j) = (fc/f)^5*(alpha*(g^2)*((2*pi)^(-4))*(f^(-5)))*exp((-5/4)*((f/fp)^(-4)))*gamma*exp((-1/2)*((f-fp)/(delta_2*fp))^2);
end
else
E(i,j)=0;
end
end
end
E;
%%% Dir(teta)
i_teta=1:36;
teta_i=10.*i_teta;
teta_i_cos=cos(2*teta_i);
for i = 1:length(teta_i_cos)
if teta_i_cos>0
dir_teta=0;
else
dir_teta= (2/pi())*(1/2)*(1+teta_i_cos);%cos^2(x) = (1+cos2x)/2
end
end
dir_teta;
f_teta=teta_i;
%%%%%%%%%%%%% My problem below %%%%%%%%%%%%%%%%%%%%
%%% T=2s
T2=E(:,1);
T2(T2==0)=1;%changed all T2 values that were 0 to 1 (if you multiply by zero everything below will be zero)
%when I ran it without this, the whole 69x36 matrix was zeros
aux_T2=cumprod(T2)*dir_teta;
Jacqueline Rigatto
il 11 Nov 2020
David Hill
il 11 Nov 2020
What do you do with the zero data within your table? What you are describing in red does not match your orginal question and is still confusing. Does Q4=Q1*O3*O4? That was how you described it. Or are you not placing the values into the array as you go such that Q4=orginal(Q3)*O4? What are you doing for all the white space above (between Q9 and Q12, R5 and R12, ...)?
Jacqueline Rigatto
il 11 Nov 2020
Jacqueline Rigatto
il 11 Nov 2020
Jacqueline Rigatto
il 11 Nov 2020
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
