Is it possible to do a for loop of this code?

1 view (last 30 days)
Hi,
sigma1cm0 = std(cm0_1); sigma1cmA = std(cmA_1);
sigma1cmq = std(cmq_1); sigma1cmE = std(cmE_1);
The size of cm0/A/q/E its all the same
>> size(cm0_1)
ans =
4 1
all 1 to 3 (three sets, from three different datas: cm0_1,cm0_2,cm0_3 and cmq_1,cmq_2 and so on ) and maybe each letter, as they have 'cm' in common? (0,A,q,E) Thanks
  2 Comments
Roger Stafford
Roger Stafford on 11 Dec 2014
Edited: Roger Stafford on 11 Dec 2014
Your computations seem entirely normal, but could you please state your question in more detail. I don't understand what you are asking. In particular what is it you mean by "1 to 3 and maybe each letter? (0,A,q,E)" or "Is it possible to loop this" ?
Andil  Aboubakari
Andil Aboubakari on 11 Dec 2014
Edited: Andil Aboubakari on 11 Dec 2014
That code is only a third of what it should be. I have another two set which is exactly the same but all the 1 changes to 2 (second set) and then 3.
So I was asking if its possible to avoid the repetition and loop one line through all the four letters three times, roughly like this:
letter={'0';'A';'q';'E'}
for ii=1:3
for jj=1:numel(letter)
sigma(ii)cm(letter(jj))=std(cm(letter(jj)_(ii))
cm(letter(jj)(ii))=max(cm(letter(jj)_(ii))
cm(letter(jj)(ii))=min(cm(letter(jj)_(ii))
end
end
Obviously that not the right way for sure.

Sign in to comment.

Accepted Answer

dpb
dpb on 11 Dec 2014
...if its possible to avoid the repetition and loop one line through all the four letters...
"Possible", yes, but "there be dragons" that way...
for why and alternatives. I think newer doc has a discussion under eval of the topic as well. For this case probably the alternative of dynamically-named structure is good choice.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!