How to correct the error Matlab says i've done?

bsd Hello, here are the codes i'm using, Avodakodnew is the one i run, euler is needed for Avodakodnew. Here is the error i get when i try to run it:
>> Avodakodnew(5.5)
Subscripted assignment dimension mismatch.
Error in Avodakodnew (line 46) gu(i,j) = etha * ku(i,j) * diff ( u(i,j+1) - u(i,j), t ); %upper
What does this mean?
When i do >> ndims(gu), i get:
ans = 2
but if i ask for >> ndims(gu(i,j)), i get an error:
Subscript indices must either be real positive integers or logicals.
Anybody could help me to understand and correct that,please?

 채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 18일

0 개 추천

Your c6 is a vector or matrix but you are trying to assign it into the single location gu(i,j). Or possibly c6 is empty.
We need to know: are the "u" values symbolic or numeric? If they are symbolic then diff(c3,t) makes sense in itself, but each "gu" will be symbolic when generated. If the "u" values are numeric, then diff(c3,t) is going to ask for the "t'th" numeric difference, and since you are passing in a scalar expression, if "t" does not happen to be a positive integer you would get an error message from diff(), and if "t" does happen to be a positive integer, then the diff() of a scalar is going to be empty.

댓글 수: 1

You cannot differentiate a numeric vector with respect to time. When you apply diff() to a numeric vector, you get the Difference function, not Differentiation. diff(x) with no second argument and with x numeric, means
[x(2:end) - x(1:end-1)]
It is possible that you want to know the gradient in numeric form. If so and if "t" is a vector of time values that correspond to u values, use gradient()

댓글을 달려면 로그인하십시오.

추가 답변 (6개)

Andreas Goser
Andreas Goser 2013년 10월 16일
편집: Andreas Goser 2013년 10월 16일

0 개 추천

Could be multiple things in
etha * ku(i,j) * diff ( u(i,j+1) - u(i,j), t );
My gut feeling is you want to use .* instead of * in at least one of the operations.

댓글 수: 2

Odelia
Odelia 2013년 10월 16일
편집: Odelia 2013년 10월 16일
Thanks, but no, there is still the same error.
I can keep on guessing like you use i and j without assigning them first and MATLAB treats them as complex numbers, but first and foremost, in order to resolve this one needs code AND data.

댓글을 달려면 로그인하십시오.

Jan
Jan 2013년 10월 16일
편집: Jan 2013년 10월 17일

0 개 추천

The problem is concealed anywhere in this line. So split the line into its parts to find out, where the problem is:
c1 = u(i,j+1);
c2 = u(i,j);
c3 = c1 - c2;
c4 = diff(c3, t);
c5 = etha * ku(i,j);
c6 = c5 * c4;
gu(i,j) = c6;
Now find out which step fails.

댓글 수: 4

Jan, you are again too kind ;-)
Jan
Jan 2013년 10월 17일
But not kind enough to trust, that the users know how to debug their code.
bsd
Ok, thanks for the idea. The error is in the last line, in Matlab words:
>> Avodakodnew(5.5)
Subscripted assignment dimension mismatch.
Error in Avodakodnew (line 52)
gu(i,j) = c6; %upper
I don't understand what i'm supposed to do then.
I don't know what bsd means, but this will help http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/. That will definitely solve it but in case you don't want to do that, you can put these lines before that gu line:
whos i
whos j
whos c6

댓글을 달려면 로그인하십시오.

Siavash Kardar Tehran
Siavash Kardar Tehran 2013년 10월 17일

0 개 추천

firt of all make sure when you're using "for" command the vectors start their indices from 1, I mean Matlab doesn't recognize gu(0) and it must start at gu(1);
also make sure u(i,j+1) doesn't exceed you matrix dimensions.
I hope this could help.

댓글 수: 1

Odelia
Odelia 2013년 10월 17일
bsd
What does "u(i,j+1) doesn't exceed the matrix dimensions" mean? How can I check that?

댓글을 달려면 로그인하십시오.

Odelia
Odelia 2013년 10월 21일

0 개 추천

bsd [-> this is not connected to the problem, that means "with the help of G-od" :) ]
Hello everybody,
  • i and j are as follows:
for i = 3 : x
for j = 2 : (N+2)/2-1
when N=6.
  • u is really numeric because the problem has initial conditions, it looks like this:
u = [delta*ones(1,x);delta*ones(N/2,2) Z1;(-delta)*ones(N/2,2) Z2;(-delta)*ones(1,x)];
with
Z1 = [5*delta/(N+1)*ones(1,x-2);3*delta/(N+1)*ones(1,x-2);delta/(N+1)*ones(1,x-2)];
and
Z2 = [(-delta)/(N+1)*ones(1,x-2);(-3*delta)/(N+1)*ones(1,x-2);(-5*delta)/(N+1)*ones(1,x-2)];
delta is the input.
(you can see the whole code in the attached file "Avodakodnew" in the first message)
But with the time, u is supposed to change, that's why i have diff( ,t).
  • whos iwhos jwhos c6really gives:
>> Avodakodnew(5.5) Name Size Bytes Class Attributes
i 1x1 8 double
Name Size Bytes Class Attributes
j 1x1 8 double
Name Size Bytes Class Attributes
c6 0x0 0 double
  • I'm working on a physical problem i have to translate into matlab. I can't see how i'm supposed to modify this code.
Thank you for your help, it's precious ;-)
Odelia
Odelia 2013년 11월 6일

0 개 추천

בס"ד
Hello,
Walter Roberson was right, i just needed to use gradient instead of diff. Thank you all.
Odelia
Odelia 2013년 11월 6일
편집: Odelia 2013년 11월 6일

0 개 추천

בס"ד
Hi again,
Another error has appeared:
_Error using *
Inner matrix dimensions must agree.
Error in euler (line 25)
miu(n,:) = miu(n-1,:) + nu(n-1,:) * dt;_
If i add a point:
_Error using .*
Matrix dimensions must agree.
Error in euler (line 28)
miu(n,:) = miu(n-1,:) + nu(n-1,:) .* dt;_
Using whos, i get the same dimensions for miu, nu and dt. Does anybody know what this error message means?
Data is defined as follows:
_t0 = ones ( N+2, x+1 ) ;
t = t0 : 10*t0 ;
dt = ( 10*t0 - t0 )/ .1 ;
miu = u ;
nu = v ;_
(u and v are also ( N+2, x+1 ) )
n = 2 : length(t)
Thank you,

카테고리

질문:

2013년 10월 16일

편집:

2013년 11월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by