how can i keep loop times in my for loop

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 Kommentar

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);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 16 Dez. 2012

1 Stimme

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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 16 Dez. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by