필터 지우기
필터 지우기

Loop with row and column difference (multiplication)

조회 수: 1 (최근 30일)
Jacqueline Rigatto
Jacqueline Rigatto 2020년 11월 10일
댓글: Jacqueline Rigatto 2020년 11월 12일
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
David Hill
David Hill 2020년 11월 10일
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
Jacqueline Rigatto 2020년 11월 10일
My script

댓글을 달려면 로그인하십시오.

답변 (2개)

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

David Hill
David Hill 2020년 11월 10일
편집: David Hill 2020년 11월 10일
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
Jacqueline Rigatto
Jacqueline Rigatto 2020년 11월 11일
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 2020년 11월 11일
And I'm sorry for the confusion I made.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by