From: CyberFrog on
Hi all,

Any idea why my loop index is not updating, I can't see what is wrong with my code:
f=1;
list='5','25',56'; %required line numbers
p='100'; %last line number

%always starts on chosen line numbers i.e. list{1}=line 5
%z identifies when the desires data has been read and now requires to read the next
%desired line number 25. However, why does x not update? Is there aanother way to do this
for x=list{f}:p
z = findstr(data{x},'PAGE);
if z > 0
f=f+1;
else
fprintf(fid1,'%s\n',data{x});
end
end

To explain what is
From: Husam Aldahiyat on


list=['5','25',56']; %required line numbers
From: CyberFrog on
"Husam Aldahiyat" <numandina(a)gmail.com> wrote in message <hnl3ke$42m$1(a)fred.mathworks.com>...
>
>
> list=['5','25',56']; %required line numbers

Hi Husam,

I have used this but it still doesn't make a difference to my loop, its still doesn't seem to jump from the current indice or line number it last read to the next desired line number i..e 25. So for example if it reads in all lines from 5 to 15, I would then expect my for x indix to jump to 25. What is strange is when I hover my cursor over the list{k} inital variable it does pick this next line number up but x just simply increments by one each time and so it doesn't make the jump.
From: Jan Simon on
Dear CyberFrog!

> Any idea why my loop index is not updating, I can't see what is wrong with my code:
> f=1;
> list='5','25',56'; %required line numbers
> p='100'; %last line number
>
> %always starts on chosen line numbers i.e. list{1}=line 5
> %z identifies when the desires data has been read and now requires to read the next
> %desired line number 25. However, why does x not update? Is there aanother way to do this
> for x=list{f}:p
> z = findstr(data{x},'PAGE);
> if z > 0
> f=f+1;
> else
> fprintf(fid1,'%s\n',data{x});
> end
> end
>
> To explain what is

This is definitely not Matlab code!
1. list='5','25',56'
This perform
list = '5';
and the rest is sent to tumbolia.

2. for x=list{f}:p
[list] is not a cell, so you cannot access elements with curly braces.
If [list] would be a cell, than this line would perform:
for x = '5':'100'
but '5' is a 1 x 1 char arry, while '100' is a 1 x 3 char array. Therefore the colon operator must fail.

Please look in the documentation of FOR again ("doc for") and post your next approach again!

Kind regards, Jan
From: Walter Roberson on
CyberFrog wrote:

> I have used this but it still doesn't make a difference to my loop, its
> still doesn't seem to jump from the current indice or line number it
> last read to the next desired line number i..e 25.

Your for loop had f as an index, and you update f in the loop, and you
are expecting the for loop to change its range in response. That will
not happen. When you start a for loop. matlab calculates the beginning
and the end value right then, and stores them internally, and never
changes them in response to anything that happens in the loop.

What you should do in your case is something like:

for f = 1 : 3
for i = list(f):whatever...
if (you should go to the next f)
break
end
process for this i
end
end