matlab图画不出来,Error using plot Vectors must be the same length
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/16 00:59:16
matlab图画不出来,Error using plot Vectors must be the same lengths.Error in Untitled (line 23) p
H1=20;H2=20;H3=20;g=9.8
h1 =[ ];h2=[ ];h3=[];
for t =0:0.01:10
if (sqrt(H1)-0.5*sqrt(2*g*t))> 0
h1 =[h1,(sqrt(H1)-0.5*sqrt(2*g*t)).^2];
else
h1 = [h1,0];
end
if (sqrt(H2+H1-h1)-0.5*sqrt(2*g*t))> 0
h2 = [h2,(sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2];
else
h2 =[h2,0];
end
if (sqrt(H3+H2-h2)-0.5*sqrt(2*g*t))> 0
h3 = [h3,(sqrt(H3+H2-h2)-0.5*sqrt(2*g*t)).^2];
else
h3 =[h3,0];
end
end
t=0:0.01:10;
subplot(2,2,1)
plot(t,h1);
subplot(2,2,2)
plot(t,h2);
subplot(2,2,3)
plot(t,h3);
H1=20;H2=20;H3=20;g=9.8
h1 =[ ];h2=[ ];h3=[];
for t =0:0.01:10
if (sqrt(H1)-0.5*sqrt(2*g*t))> 0
h1 =[h1,(sqrt(H1)-0.5*sqrt(2*g*t)).^2];
else
h1 = [h1,0];
end
if (sqrt(H2+H1-h1)-0.5*sqrt(2*g*t))> 0
h2 = [h2,(sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2];
else
h2 =[h2,0];
end
if (sqrt(H3+H2-h2)-0.5*sqrt(2*g*t))> 0
h3 = [h3,(sqrt(H3+H2-h2)-0.5*sqrt(2*g*t)).^2];
else
h3 =[h3,0];
end
end
t=0:0.01:10;
subplot(2,2,1)
plot(t,h1);
subplot(2,2,2)
plot(t,h2);
subplot(2,2,3)
plot(t,h3);
Error using plot Vectors must be the same lengths.
意思是t和h1,h2,h3的长度不是一致的.
到底问题出在哪里?
你的h1的值计算是没有错的,长度是一致的,
但是你的h2和h3的值所得出来的矩阵元素个数却大的惊人,
h2 = [h2,(sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2];
你看看,如果你的h1有n个元素,那么你的h2将最大有n(n+1)/2个元素,而你的h3中的元素将更大.
我粗略的理解了一下你的意思.
对于每一个t求出其当前的h1值,
将h1值代入sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2中来判断当前h2取0还是取sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2
再根据当前h2的值来确定当前h3的值.
那么很显然你的错误就是,没有把当前定义好.
下面给出代码:
H1=20;H2=20;H3=20;g=9.8;
h1 =[ ];h2=[ ];h3=[];
i=0;
for t =0:0.01:10
i=i+1;%%设置下标,来表示当前h1,h2,h3的元素
if (sqrt(H1)-0.5*sqrt(2*g*t))> 0 %%计算当前h1
h1(i)=(sqrt(H1)-0.5*sqrt(2*g*t)).^2;
else
h1(i) = 0;
end
if (sqrt(H2+H1-h1(i))-0.5*sqrt(2*g*t))> 0 %%计算当前h2
h2(i) = (sqrt(H2+H1-h1(i))-0.5*sqrt(2*g*t)).^2;
else
h2(i) =0;
end
if (sqrt(H3+H2-h2(i))-0.5*sqrt(2*g*t))> 0 %计算当前h3
h3(i) = (sqrt(H3+H2-h2(i))-0.5*sqrt(2*g*t)).^2;
else
h3(i)=0;
end
end
t=0:0.01:10;
subplot(2,2,1)
plot(t,h1);
subplot(2,2,2)
plot(t,h2);
subplot(2,2,3)
plot(t,h3);
你先看看,
意思是t和h1,h2,h3的长度不是一致的.
到底问题出在哪里?
你的h1的值计算是没有错的,长度是一致的,
但是你的h2和h3的值所得出来的矩阵元素个数却大的惊人,
h2 = [h2,(sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2];
你看看,如果你的h1有n个元素,那么你的h2将最大有n(n+1)/2个元素,而你的h3中的元素将更大.
我粗略的理解了一下你的意思.
对于每一个t求出其当前的h1值,
将h1值代入sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2中来判断当前h2取0还是取sqrt(H2+H1-h1)-0.5*sqrt(2*g*t)).^2
再根据当前h2的值来确定当前h3的值.
那么很显然你的错误就是,没有把当前定义好.
下面给出代码:
H1=20;H2=20;H3=20;g=9.8;
h1 =[ ];h2=[ ];h3=[];
i=0;
for t =0:0.01:10
i=i+1;%%设置下标,来表示当前h1,h2,h3的元素
if (sqrt(H1)-0.5*sqrt(2*g*t))> 0 %%计算当前h1
h1(i)=(sqrt(H1)-0.5*sqrt(2*g*t)).^2;
else
h1(i) = 0;
end
if (sqrt(H2+H1-h1(i))-0.5*sqrt(2*g*t))> 0 %%计算当前h2
h2(i) = (sqrt(H2+H1-h1(i))-0.5*sqrt(2*g*t)).^2;
else
h2(i) =0;
end
if (sqrt(H3+H2-h2(i))-0.5*sqrt(2*g*t))> 0 %计算当前h3
h3(i) = (sqrt(H3+H2-h2(i))-0.5*sqrt(2*g*t)).^2;
else
h3(i)=0;
end
end
t=0:0.01:10;
subplot(2,2,1)
plot(t,h1);
subplot(2,2,2)
plot(t,h2);
subplot(2,2,3)
plot(t,h3);
你先看看,
matlab图画不出来,Error using plot Vectors must be the same length
求matlab高手~Error using plot Vectors must be the same lengths问
新手使用matlab出现Error using ==> plot Vectors must be the same le
MATLAB运行错误:Error using plot Vectors must be the same lengths
关于出现 MATLAB Error using ==> plot Vectors must be the same le
求解释: MATLAB Error using ==> plot Vectors must be the same le
Matlab Error using ==> plot Vectors must be the same lengths
matlab 提示错误是:Error using ==> plot Vectors must be the same l
MATLAB 错误?Error using ==> plot3 Vectors must be the same len
matlab plot 提示错误:Vectors must be the same lengths!
matlab中关于统计回归多元回归模型如何求解,总是出现Error using plot Vectors must be
哪位大侠知道这个MATLAB的错误啊 plot Vectors must be the same lengths.