From: Travis on
I'm trying to read a generic mesh file which is structured like:

1 5.00000000000e+00 0.00000000000e+00 5.00000000000e+00

to do so I've got:

i=0;
for r = 1:R
if (r > (eos(1)+1) && r < eos(2))
i = i + 1;
node(i,:) = fscanf(fid,'%f %f %f %f');
end
end

Where R is the total number of lines and eos(1) and eos(2) are the start and endpoint of what I want to read.

I'm having 2 problems 1 is that no data is being read, I know this because when I change node(i,:) to node there is no data. Also I'm getting an error when trying to read this:

??? Subscripted assignment
dimension mismatch.

Error in ==> ReadMesh at 55
node(i,:) =
fscanf(fid,'%f %f %f
%f');
From: Walter Roberson on
Travis wrote:
> I'm trying to read a generic mesh file which is structured like:
>
> 1 5.00000000000e+00 0.00000000000e+00 5.00000000000e+00
>
> to do so I've got:
>
> i=0;
> for r = 1:R
> if (r > (eos(1)+1) && r < eos(2))
> i = i + 1;
> node(i,:) = fscanf(fid,'%f %f %f %f'); end
> end
>
> Where R is the total number of lines and eos(1) and eos(2) are the start
> and endpoint of what I want to read.

for r = 1 : eos(1) + 1; fgetl(fid); end
node = textscan(fid, '%f %f %f %f', (eos(2) - 1) - (eos(1) + 1), 'Collect', 1)

But please recheck your logic for eos. If, for example, eos(1) is 2 and eos(2)
is 5, then the first clause of your current "if" statement is not true until
r > (2+1) which would not occur until r = 4; the second clause of your "if"
statement stops _before_ eos(2) and so would end at r = 4 with my sample
values, leaving only one line to be processed even though the start and stop
values are numerically 3 apart for this example.