Subscripted assignment dimension mismatch

1 次查看(过去 30 天)
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 个)

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