How to save the answer that is generated in a triple for loop?

조회 수: 1 (최근 30일)
Nikhil Murali Krishnaa
Nikhil Murali Krishnaa 2019년 6월 4일
편집: Nikhil Murali Krishnaa 2019년 6월 4일
I need to compare two signal each time for various combinations and find the best signal that correlates. But saving the answer is overwriting everytime in the loop. How do i save the answer in a matrix so that later i can get the max value from it. This is my code now;
peaks = cell(450,1);
for K1 = 170000:5000:210000
kn = numel(K1);
for B1 = 1:10:100
bn = numel(B1);
for M1 = 1:0.05:1.2
mn = numel(M1);
S=sim('MSDsystem');
Display=S.Displacement(:,2);
Mass=Mass1(:,2)/1000000;
[c,lag]=xcorr(Mass,Display);
peak = max(c);
peaks{1i} = peak ;
end
end
end

답변 (1개)

Raj
Raj 2019년 6월 4일
Just add one more loop to index the 'peaks' something like this:
for ii=1:numel(peaks)
for K1 = 170000:5000:210000
kn = numel(K1);
for B1 = 1:10:100
bn = numel(B1);
for M1 = 1:0.05:1.2
mn = numel(M1);
S=sim('MSDsystem');
Display=S.Displacement(:,2);
Mass=Mass1(:,2)/1000000;
[c,lag]=xcorr(Mass,Display);
peak = max(c);
peaks{ii} = peak ;
end
end
end
end
Then outside the loops use this:
peaks=str2double(peaks);
MaxPeak=max(peaks)
Is this what you are looking for?
  댓글 수: 3
Raj
Raj 2019년 6월 4일
Loop stops at 450. There is no reason for loop to run infinitely. Please check again.
Nikhil Murali Krishnaa
Nikhil Murali Krishnaa 2019년 6월 4일
편집: Nikhil Murali Krishnaa 2019년 6월 4일
Thanks for your reply. But i checked it. It runs 450*450 times. 202500times

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by