Matlab, loop for. Problem.

1 回表示 (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by