From: amina on
Hi Sorry

I forgot to write the error message.

Here is what i am doing:

The code is:

for i = 1: length(path)
fprintf('Path # %d:\n',i);
disp(path{i})
fprintf('dist of path %d is %d\n\n',i,dist(i));
end
end

The output is:

Path # 1:
1 2

dist of path 1 is 10

Path # 2:
1 4 5 2

dist of path 2 is 30

Now i want to assign the path i-e 1 2 and 1 4 5 2 to the variable
newp.

So i write:

for g = 1: length(path)
newp = path(g);
end

But i get the error : ??? Index exceeds matrix dimensions. path =
path(g);

Sorry again for not writing the error message before.

Please help.
From: Walter Roberson on
amina wrote:

> So i write:
>
> for g = 1: length(path)
> newp = path(g);
> end
>
> But i get the error : ??? Index exceeds matrix dimensions. path =
> path(g);

The error message you quote disagrees with your code. The error message
says that your code is

path = path(g);

whereas you have shown us

newp = path(g);

If you do have

path = path(g);

then the error message becomes unsurprising, as you are overwriting path
and so in the second iteration there path(2) would not exist.

Note by the way that according to your printing loop, path is a cell
array rather than a simple numeric matrix. If you want to copy a single
cell to newp, resulting in newp being a 1x1 cell array, then

newp = path(g);

is appropriate. I suspect, though, that you want to get at the contents
of the cell, via path{g} .

If you want to copy the entire path cell array to newp then just do it
in one step instead of using a for loop:

newp = path;
First  |  Prev  | 
Pages: 1 2
Prev: roundoff in version 7.7.0
Next: pcolor in Matlab