Azzera filtri
Azzera filtri

Loop with row and column difference (multiplication)

1 visualizzazione (ultimi 30 giorni)
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
David Hill
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');

Accedi per commentare.

Risposte (2)

Cris LaPierre
Cris LaPierre il 10 Nov 2020
Assuming you meant to include a Q2, I'd do this using cumprod instead of a for loop.

David Hill
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
Jacqueline Rigatto
Jacqueline Rigatto il 11 Nov 2020
I managed to do it using the code:
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';
aux1=cumprod(dir_teta');
aux2=repmat(aux1,1,69);
aux3=aux2.*T2;
Thank you for your help David Hill
Jacqueline Rigatto
Jacqueline Rigatto il 11 Nov 2020
And I'm sorry for the confusion I made.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by