hello i need an if function that tells matlab to reject a certain value and continue to the next one under a condition
2 次查看(过去 30 天)
显示 更早的评论
for example if
TEL =
1.0e+04 *
2.2786 1.7122 1.3066 1.0110 0.7922 0.6278 0.5027 0.4063 0.2723 0.1880 0.1331 0.0964 0.0712
2.2558 1.6950 1.2935 1.0009 0.7842 0.6215 0.4976 0.4022 0.2696 0.1861 0.1318 0.0955 0.0705
2.2330 1.6779 1.2805 0.9908 0.7763 0.6152 0.4926 0.3982 0.2668 0.1842 0.1305 0.0945 0.0698
2.2102 1.6608 1.2674 0.9807 0.7684 0.6089 0.4876 0.3941 0.2641 0.1823 0.1291 0.0935 0.0691
2.1874 1.6437 1.2543 0.9706 0.7605 0.6026 0.4825 0.3901 0.2614 0.1805 0.1278 0.0926 0.0684
2.1646 1.6265 1.2413 0.9605 0.7525 0.5964 0.4775 0.3860 0.2587 0.1786 0.1265 0.0916 0.0676
i want matlab to compare the first value in each iteration with a number let's just say 1080 so..
if TEL>1080
reject it and move on to the next iteration.
0 个评论
回答(2 个)
Image Analyst
2019-2-22
What iteration??? Is this in a while or for loop???
By first value do you mean TEL(1)?
Please clarify!
Maybe you want to use if and continue to compare EVERY value of TEL with 1080????
for index = 1 : length(TEL)
if TEL(index) > 1080
% Skip remainder of loop and pick up with the next index.
continue;
end
% Code to do if TEL <= 1080.....
end
2 个评论
Image Analyst
2019-2-22
So TEL is a 2D array and you want to check the first column in each row to see if it's more than MaxHead. Then do the first loop 13 times until you have finished creating TEL. Then try
for row = 1 : size(TEL, 1)
% Check if first element in this row is more than MaxHead.
% If it it, skip this loop and check the next row.
if TEL(row, 1) > MaxHead
% Skip remainder of loop and pick up with the next index.
continue;
end
% Code to do if TEL <= MaxHead.....
end
Of course you could put this into the first loop if you want - it depends on what else happens in your first loop and if that needs to happen before checking the value of TEL, or not.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!