How to remove this error??
1 回表示 (過去 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!