Prev: roundoff in version 7.7.0
Next: pcolor in Matlab
From: amina on 1 Jun 2010 12:02 Hi I have a very simple/naive question. I am using a code(written below) to calculate the shortest paths between two network nodes. 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 I get the paths along with their costs: Path # 1: 1 2 cost of path 1 is 10 Path # 2: 1 4 5 2 cost of path 2 is 30 After getting the paths and their cost i want to assign Path #1 and Path #2 to a new variable lets say newp. for g = 1:2 newp = (Path(g)); end But i always get the error. Can anyone please help me.
From: someone on 1 Jun 2010 12:28 amina <hayatamina23(a)gmail.com> wrote in message <e97fc5e3-b6b3-435d-aaf5-21f10e5ee84c(a)a16g2000vbr.googlegroups.com>... > Hi > > I have a very simple/naive question. > > I am using a code(written below) to calculate the shortest paths > between two network nodes. > > 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 > > > I get the paths along with their costs: > > Path # 1: > 1 2 > > cost of path 1 is 10 > > Path # 2: > 1 4 5 2 > > cost of path 2 is 30 > > After getting the paths and their cost i want to assign Path #1 and > Path #2 to a new variable lets say newp. > > for g = 1:2 > newp = (Path(g)); > end > > But i always get the error. > > Can anyone please help me. What error message do you get? Perhaps you mean: newp = (path(g));
From: Walter Roberson on 1 Jun 2010 12:39 Amina wrote: > After getting the paths and their cost i want to assign Path #1 and Path #2 to a new variable lets say newp. > > for g = 1:2 > newp = (Path(g)); > end > > But i always get the error. It appears you are trying to create variable names in a loop. That is very much recommended against. http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
From: us on 1 Jun 2010 12:52 amina <hayatamina23(a)gmail.com> wrote in message <e97fc5e3-b6b3-435d-aaf5-21f10e5ee84c(a)a16g2000vbr.googlegroups.com>... > Hi > > I have a very simple/naive question. > > I am using a code(written below) to calculate the shortest paths > between two network nodes. > > 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 > > > I get the paths along with their costs: > > Path # 1: > 1 2 > > cost of path 1 is 10 > > Path # 2: > 1 4 5 2 > > cost of path 2 is 30 > > After getting the paths and their cost i want to assign Path #1 and > Path #2 to a new variable lets say newp. > > for g = 1:2 > newp = (Path(g)); > end > > But i always get the error. > > Can anyone please help me. well... how can CSSMers be of any help if you don't show the full error stream(?)... us
From: John D'Errico on 1 Jun 2010 13:03
amina <hayatamina23(a)gmail.com> wrote in message <e97fc5e3-b6b3-435d-aaf5-21f10e5ee84c(a)a16g2000vbr.googlegroups.com>... > Hi > > I have a very simple/naive question. > > I am using a code(written below) to calculate the shortest paths > between two network nodes. > > 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 > > > I get the paths along with their costs: > > Path # 1: > 1 2 > > cost of path 1 is 10 > > Path # 2: > 1 4 5 2 > > cost of path 2 is 30 > > After getting the paths and their cost i want to assign Path #1 and > Path #2 to a new variable lets say newp. > > for g = 1:2 > newp = (Path(g)); > end > > But i always get the error. > > Can anyone please help me. Regardless of the resolution, it is a BADDDD idea to use the name path for a variable name, as that overshadows the useful function path. Try to avoid doing things like this. As far as you actual problem goes, you cannot assign a vector to an element of a double array. So learn to use cell arrays instead for this assignment. John |