필터 지우기
필터 지우기

Subscripted assignment dimension mismatch

조회 수: 1 (최근 30일)
Fatima Al Marzoqi
Fatima Al Marzoqi 2014년 7월 9일
댓글: dpb 2014년 7월 10일
What is the problem with my code ?
When I run it, at first time it works normally and displayed the output as expected
but at the second time it displayed the following error
I tryed to re-open the MATLAB ..
but if I try the code twice it display the error , but if only once everything displayed as expected
Error in proj (line 147)
p3(k2,:)=xcur';
CODE
%Initial condition
xcur=(B*cur)+c;
p3(k2,:)=xcur';
fprintf(fid,'%3.6f\t%0.6f\t%0.6f\t',xcur);
curnorm=xcur-cur;
%Finding the norm
max3=0;
for i=1:4;
if abs(curnorm(i,1))>max3;
max3=abs(curnorm(i,1));
end
end
p4(k2,1)= max3; %For plotting
fprintf(fid,'%3.6f\n',max3);
if max3 >T;
condition3=1;
else
condition3=0;
end
cur=xcur;
end
for i=1:4
p3(i,4+1)=p4(i,1);
end
  댓글 수: 2
Ben11
Ben11 2014년 7월 9일
In your last for-loop is it really
for i=1:4
p3(i,4+1)=p4(i,1);
end
that you want to write? The second index to p3 is actually 5 so maybe this causes the error?
Fatima Al Marzoqi
Fatima Al Marzoqi 2014년 7월 10일
the code works fine if I run it once only . . if I want to run it another time , I should re-open the matlab
is this the solution?

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

답변 (1개)

dpb
dpb 2014년 7월 9일
xcur=(B*cur)+c;
p3(k2,:)=xcur';
xcur.' must be a column vector of the same length as that the first time on each subsequent pass. There's insufficient data presented to tell just what any dimensions are.
Use
dbstop on error
and see what the sizes of the terms are. That will, in all likelihood, reveal the logic error.
  댓글 수: 2
Fatima Al Marzoqi
Fatima Al Marzoqi 2014년 7월 10일
the code works fine if I run it once only . . if I want to run it another time , I should re-open the matlab
is this the solution?
dpb
dpb 2014년 7월 10일
Is that what the Answer I gave says? No, I didn't think so... :(

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by