Matlab, loop for. Problem.

조회 수: 2 (최근 30일)
Przemek Tomaszewski
Przemek Tomaszewski 2018년 8월 30일
댓글: Anusha Sridharan 2019년 1월 9일
Hi.
How to simplify the bolded code. I would like to put it in a loop. But it does not really work out. Maybe someone will tell you.
In the attachment I added the data (Ma and Nf) need for the program.
for i=1:10
Moment_sredni(:,i)=mean(Ma((10:130),i));
Moment_NF(:,i)=Moment_sredni(i)/1.15;
ind(:,i)=Ma(:,i)<Moment_NF(:,i);
end
I would like the code below to simplify and put in a loop
Nf1=Nf(:,1); trwalosc1=Nf1(ind(:,1)); TRWALOSC1=trwalosc1(1);
Nf2=Nf(:,2); trwalosc2=Nf2(ind(:,2)); TRWALOSC2=trwalosc2(1);
Nf3=Nf(:,3); trwalosc3=Nf3(ind(:,3)); TRWALOSC3=trwalosc3(1);
Nf4=Nf(:,4); trwalosc4=Nf4(ind(:,4)); TRWALOSC4=trwalosc4(1);
Nf5=Nf(:,5); trwalosc5=Nf5(ind(:,5)); TRWALOSC5=trwalosc5(1);
Nf6=Nf(:,6); trwalosc6=Nf6(ind(:,6)); TRWALOSC6=trwalosc6(1);
Nf7=Nf(:,7); trwalosc7=Nf7(ind(:,7)); TRWALOSC7=trwalosc7(1);
Nf8=Nf(:,8); trwalosc8=Nf8(ind(:,8)); TRWALOSC8=trwalosc8(1);
Nf9=Nf(:,9); trwalosc9=Nf9(ind(:,9)); TRWALOSC9=trwalosc9(1);
Nf10=Nf(:,1); trwalosc10=Nf10(ind(:,10)); TRWALOSC10=trwalosc10(1);
  댓글 수: 1
Anusha Sridharan
Anusha Sridharan 2019년 1월 9일
[Answers Dev] Restored edits

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

채택된 답변

OCDER
OCDER 2018년 8월 30일
DO NOT label your variables Nf1, Nf2, .... Var1, Var2, ...
Use cell arrays like this:
NfC = cell(1, size(Nf,2));
trwalosc = cell(size(NfC));
TRWALOSC = cell(size(NfC)); %You sure you want to label 2 variable with similar names, different by caps?
for j = 1:size(Nf, 2)
NfC{j} = Nf(:,j);
trwalosc{j} = NfC{j}(ind(:, j));
TRWALOSC{j} = trwalosc{j}(1);
end
  댓글 수: 1
Przemek Tomaszewski
Przemek Tomaszewski 2018년 8월 30일
Thank you very much for your help :) Everything works as it should.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by