For Programmers: Free Programming Magazines  


Home > Archive > Matlab > February 2007 > matris error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author matris error
ezgierdo@gmail.com

2007-02-28, 7:14 pm

Dear All,
I have written code in loops and statements.but (x,n)=(x,n)+p can not
be admitted by Matlab.Here are errors.Any idea about matris
calculating?Errors are written.
**********
k=1
nmax=6+1
for n=2:nmax
for x=1:nmax-1
y=n-x
if n==2
if(x>nmax/4 & y<floor(3*nmax)/4)
p=0,4*k
elseif (x<=nmax/4 & y>=floor(3*nmax)/4)
p=k
else p=k
mat(x,n)=mat(x,n)+p %matris elements like mat(i,j)
mat(y,n)=mat(y,n)+p
mat(n,n)=mat(n,n)-p
end
end

end
end
B=mat(2:nmax,2:nmax);
**********************************
*errors1 with using B: ??? Undefined command/function 'mat'.

Error in ==> secmat1 at 12
mat(x,n)=mat(x,n)+p %matris elements like mat(i,j)

*errors 2 without using B:
?? Error: File: secmat1.m Line: 12 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.

Line 12 is: (x,n)=(x,n)+p %matris elements like mat(i,j)

Steven Lord

2007-02-28, 10:13 pm


<ezgierdo@gmail.com> wrote in message
news:1172708565.545187.190970@q2g2000cwa.googlegroups.com...
> Dear All,
> I have written code in loops and statements.but (x,n)=(x,n)+p can not
> be admitted by Matlab.Here are errors.Any idea about matris
> calculating?Errors are written.
> **********
> k=1
> nmax=6+1
> for n=2:nmax
> for x=1:nmax-1
> y=n-x
> if n==2
> if(x>nmax/4 & y<floor(3*nmax)/4)
> p=0,4*k
> elseif (x<=nmax/4 & y>=floor(3*nmax)/4)
> p=k
> else p=k
> mat(x,n)=mat(x,n)+p %matris elements like mat(i,j)
> mat(y,n)=mat(y,n)+p
> mat(n,n)=mat(n,n)-p
> end
> end
>
> end
> end
> B=mat(2:nmax,2:nmax);
> **********************************
> *errors1 with using B: ??? Undefined command/function 'mat'.
>
> Error in ==> secmat1 at 12
> mat(x,n)=mat(x,n)+p %matris elements like mat(i,j)


The first time through the FOR loops, when you reach this line, the variable
mat does not yet exist. You can't try to get the element in the xth row and
the nth column of a matrix that doesn't exist. Define mat to be something,
say an empty matrix, before you run your FOR loops.

> *errors 2 without using B:
> ?? Error: File: secmat1.m Line: 12 Column: 11
> Expression or statement is incorrect--possibly unbalanced (, {, or [.
>
> Line 12 is: (x,n)=(x,n)+p %matris elements like mat(i,j)


That's not legal MATLAB syntax. If you want to add p to both x and n, you
can do so with these two lines:

x = x + p;
n = n + p;

That's probably not going to do what you want, though. Changes to the loop
variable inside a loop will only persist until the end of the loop; when the
loop begins its next iteration, the loop variable will take on the next
value in the vector you specified in the FOR loop statement.

http://www.mathworks.com/support/so...lution=1-1UPLL1

--
Steve Lord
slord@mathworks.com


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com