how can i keep loop times in my for loop
Show older comments
for cnt:size(PSM,1) % this line gives me an error Unexpected MATLAB operator.
%anything
end
if i set
for cnt=1:size(PSM,1)
it works but my for is inside a 'while' i don't want to reset cnt everytime , i want to cnt keep it number
thanks sry for bad english
1 Comment
Jan
on 16 Dec 2012
If the surrounding while loop is important, show the corresponding code also. Currently it is not clear, what you want to achieve. Perhaps you want:
cnt = size(PSM, 1);
Answers (1)
Image Analyst
on 16 Dec 2012
You don't have a loop index. You need to have one. Do it like this:
for loopIndex = cnt : size(PSM, 1)
cnt can be 1 or any other starting value that you want. (By the way, if cnt is "count" just call it count which is very descriptive, unlike the cryptic/ambiguous cnt). The loopIndex is not reset every time. It goes in steps of 1 until it hits the last value, which is size(PSM, 1). If it takes a long time, then you need to use the code profiler, or tic and toc, to see which lines of code are taking up most of the time.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!