Info

此问题已关闭。 请重新打开它进行编辑或回答。

error in build rows of matrix

1 次查看(过去 30 天)
mohamad khazaeezade
关闭: MATLAB Answer Bot 2021-8-20
i have this code for Computing 'dim' as number of rows of 'M' : But this code gives an error:
Error using zeros Leading inputs must be numeric.
Error in Untitled3 (line 108) M=zeros(dim,9);
the code:
clc
clear all
close all
S0 =0.02;
b = 3;
Q = 29
n = 0.017
g = 9.81;
z = 0
ystart = 2
dy=0.1;
A1 = (b+z*ystart)*ystart;
P1 = b + (2*ystart*sqrt(1+z^2));
R1 = A1/P1;
T1= b+ 2*z*ystart;
D1=A1/T1;
F1 = (T1 * Q^2)/(g*(A1)^3);
Sf1 = (Q^2)*(n^2)/((R1^(4/3))*((A1)^2));
Gy1 = (1-F1)/(S0 - Sf1);
syms yc
A=(b+z*yc)*yc;
T=b+2*z*yc;
P=b+2*yc*sqrt(1+z^2);
R=A/P;
D=A/T;
eqn=(Q ^2)/g==(A^3)/(T);
y=vpasolve (eqn);
if z>0
for ii=1:6
if real(y(ii,1))>=0 , imag(y(ii,1))==0;
yc=y(ii,1);
end
end
else
for ii=1:3
if real(y(ii,1))>=0 , imag(y(ii,1))==0;
yc=y(ii,1);
end
end
end
yc;
fr = Q / (A1*sqrt(g*D1));
if fr > 1
disp('supcr')
elseif fr < 1
disp ('subcr')
elseif fr == 1
disp ('cr')
end
syms yn
An=(b+z*yn)*yn;
Tn=b+2*z*yn;
Pn=b+2*yn*sqrt(1+z^2);
Rn=An/Pn;
Dn=An/Tn;
Eq=Q==(An/n)*S0^(0.5)*(Rn)^(2/3);
yn=vpasolve(Eq,yn,1)
if yn > yc
if ystart > yn
disp ('M1')
y2=yn;
elseif ystart > yc
disp ('M2')
y2=yn;
elseif ystart < yc
disp ('M3')
y2=yc;
end
elseif yc > yn
if ystart > yc
disp ('S1')
y2=yc;
elseif ystart > yn
disp ('S2')
y2=yn;
elseif ystart < yn
disp ('S3')
y2=yn;
end
end
dim=floor((ystart-y2)/dy+1)
M=zeros(dim,9);
  1 个评论
Rik
Rik 2018-2-17
编辑:Rik 2018-2-17
As was said in the question that was deleted, you need to say what that line should do before we can give a meaningful answer. I could suggest M=zeros(max([1 dim]),9);, which would remove the error, but I can't say if that makes any sense at all for your code.
Have a read here and here. It will greatly improve your chances of getting an answer.

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by