How do get past the first interation in this nested loop?
古いコメントを表示
old=Rod_Temp_Gradient;
new=zeros(size(Rod_Temp_Gradient));
count=0;
while max(new)- min(new)<0.5
for col=length(old)
new=[mean(old(1:2)), conv(old,[1,1,1]/3,'valid'), mean(old(end-1:end))];
end
old=new;
count=count+1;
end
8 件のコメント
Rik
2018 年 2 月 2 日
If you correctly format your question (select you code and hit the {}Code button) and mention the error (all the text in red), we can help you much more easily.
KALYAN ACHARJYA
2018 年 2 月 2 日
Pls, clarify Past or Pass?
Josh Neff
2018 年 2 月 2 日
Josh Neff
2018 年 2 月 2 日
Jan
2018 年 2 月 2 日
Please do not explain, what the computer does not do, but what it does do instead.
Rik
2018 年 2 月 2 日
Can you share an example of Rod_Temp_Gradient so we can run this code to see what happens?
Josh Neff
2018 年 2 月 2 日
Matt J
2018 年 2 月 2 日
I just wanted to point out that putting the line
new=[mean(old(1:2)), conv(old,[1,1,1]/3,'valid'), mean(old(end-1:end))];
inside the following for-loop makes no sense. The loop is just repeating the exact same calculation multiple times.
for col=1:length(old)
new=[mean(old(1:2)), conv(old,[1,1,1]/3,'valid'), mean(old(end-1:end))];
end
回答 (2 件)
Rik
2018 年 2 月 2 日
The problem lies with your condition in the while command. It keeps executing while some statement is true, not until some statement is true. The problem is that you initialize new with only zeros, so the first iteration the condition is true, as max-min is 0.
Rod_Temp_Gradient=[100 96.0789439152323 92.3116346386636 88.6920436717158 85.2143788966211 81.8730753077982 78.6627861066553 75.5783741455726 72.6149037073691 69.7676326071031 67.0320046035639 64.4036421083141 61.8783391806141 59.4520547970194 57.1209063848815 54.8811636094027 52.7292424043049 50.6616992365590 48.6752255959972 46.7666427009909 44.9328964117222 43.1710523429080 41.4782911681581 39.8519041084514 38.2892885975112 36.7879441171442];
old=Rod_Temp_Gradient;
new=zeros(size(Rod_Temp_Gradient));
count=0;
while (max(new)- min(new))>0.5 || count==0
for col=length(old)
new=[mean(old(1:2)), conv(old,[1,1,1]/3,'valid'), mean(old(end-1:end))];
end
old=new;
count=count+1;
end
The trick is to force the first run with count==0 and then have the inversion of your original statement.
Jan
2018 年 2 月 2 日
0 投票
Use the debugger to step through your code line by line: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html. This allows you to examine, what's going on in which command.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!