How to remove this error??
2 次查看(过去 30 天)
显示 更早的评论
Here is my code
function [] = plot_rho()
h= zeros(80,1);
h(1,1)=1000;
density = zeros(80,1);
k=1;
while k<=80;
density(k,1) = rho(h(k,1));
h(k+1,1)= h(k,1)-10;
k=k+1;
end
plot(density,h);
grid on;
getting an error like this but I have defined density and h of same length 80 so why this error
Error using ==> plot
Vectors must be the same lengths.
Error in ==> plot_rho at 11
plot(density,h);
0 个评论
回答(2 个)
kjetil87
2013-8-18
You are indexing h as
h(k+1,1)
That way when k=80 you are assigning a new value to
h(81)=h(80,1)-10;
And thus the size of h grows to 81.
0 个评论
Image Analyst
2013-8-18
h is 81 long while density is still only 80 long. This could be easily figured out if you know how to debug programs. See this: http://blogs.mathworks.com/videos/category/gui-or-guide/ Then you will also see that your code won't even run because you didn't define rho. You never would have gotten that error with the code that you posted. So that's how I know that you are not posting the actual code you are running.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!