Subscripted assignment dimension mismatch

조회 수: 2 (최근 30일)
Mark Lupton
Mark Lupton 2012년 5월 3일
I got an error saying "Subscripted assignment dimension mismatch"
I have this:
clc
clear all
global Mw M0 H rho g theta sigma dt A Rmax
Mw=0.001; M0=0.001; H=0.1; rho=200; g=10;
cos(theta)=0.1; sigma=0.03; dt=0.0004; A=0.00005;Rmax=0.001;
Vtotal=A*H;
for i=1:20
iter=1;
Vvoid=0;
porosity=0;
while porosity < 0.2
R(iter)=Rmax*rand(1);
Vvoid= Vvoid + pi*(R(iter)^2)*H;
porosity=Vvoid/Vtotal;
iter=iter+1;
end
Z=zeros(iter-1,2001);
for t=2:2001
sum=0; sum1=0;
for k=1:iter-1
[Z(k,t)]=Zcalculator(R(k),Z(k,t-1));
sum = sum + pi*(R(k)^2)*Z(k,t);
sum1 = sum1 + pi*(R(k)^2)*H;
end
recovery(i,t)=100*(sum/sum1);
end
end
&&&&&& and my error reads as follows::
??? Subscripted assignment dimension mismatch.
Error in ==> GroupProject at 29
[Z(k,t)]=Zcalculator(R(k),Z(k,t-1));
% does anyone know what is going on???
  댓글 수: 1
Thomas
Thomas 2012년 5월 3일
what is the function Zcalculator?

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

답변 (1개)

Geoff
Geoff 2012년 5월 3일
Enter the command:
dbstop if error
Now run your script and wait for it to break.
Then, in the command window, execute the line:
Zcalculator(R(k),Z(k,t-1));
Is it a scalar? Probably not. You are assigning to Z(k,t), which expects a scalar (because you are asking MatLab to put a value into a single element of Z).
By the way, you don't need to put square brackets around Z(k,t) when you do the assignment.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by