Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I define more than one matrix as i= on for loop?

1 回表示 (過去 30 日間)
Franchesca
Franchesca 2014 年 5 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have these 3 loops:
for i = jumph
SJvsSJWA = ttest2(i(ref(:,3)),i(ref(:,1)));% jump height
CJvsCJWA = ttest2(i(ref(:,4)),i(ref(:,2)));
SJWAvsCJWA = ttest2(i(ref(:,1)),i(ref(:,2)));
SJvsCJ = ttest2(i(ref(:,3)),i(ref(:,4)));
end
for i = avp
SJvsSJWA = ttest2(i(ref(:,3)),i(ref(:,1)));% average power
CJvsCJWA = ttest2(i(ref(:,4)),i(ref(:,2)));
SJWAvsCJWA = ttest2(i(ref(:,1)),i(ref(:,2)));
SJvsCJ = ttest2(i(ref(:,3)),i(ref(:,4)));
end
for i = peakp
SJvsSJWA = ttest2(i(ref(:,3)),i(ref(:,1)));% peak power
CJvsCJWA = ttest2(i(ref(:,4)),i(ref(:,2)));
SJWAvsCJWA = ttest2(i(ref(:,1)),i(ref(:,2)));
SJvsCJ = ttest2(i(ref(:,3)),i(ref(:,4)));
end
What I want to do is combine the 3 for loops so that for example:
i = jumph:avp:peakp
but I am aware this wouldn't work, so need a way to do this.
The three variables jumph, avp and peakp are all 54 x 1 matrices.
  3 件のコメント
Franchesca
Franchesca 2014 年 5 月 19 日
Yes the p value was the next thing I was going to tackle. And thank you I have now changed the varaible names in the second 2 loops to save all the values. Is there any way of combining the three loops?
Star Strider
Star Strider 2014 年 5 月 19 日
Is ‘i’ a loop counter (vector) or is it something else? (This may have a context I’m not familiar with.) I don’t know how your data are organised.

回答 (1 件)

Matt J
Matt J 2014 年 5 月 19 日
One way,
for i=1:54
m=jumph(i);
n=avp(i);
p=peakp(i);
%do stuff with m,n,p
end
  2 件のコメント
Franchesca
Franchesca 2014 年 5 月 19 日
I want to process the whole of column jumph on the 4 lines then the whole of avp on the 4 lines then the whole of peakp on the 4 lines. I'm not sure how this would do this, sorry.
Matt J
Matt J 2014 年 5 月 19 日
If so, then what benefit are you seeking in combining the loops? The existing code will do that already.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by