How to remove this error??

조회 수: 1 (최근 30일)
Nidhi
Nidhi 2013년 8월 18일
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);

답변 (2개)

kjetil87
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.

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by