I'm getting a plotting length mismatch error but my lengths match

조회 수: 2 (최근 30일)
Paul
Paul 2012년 12월 3일
I keep getting the following error
Error using plot
Vectors must be the same lengths.
Error in Plotting (line 43)
plot(x,y,xlabel('Distance Through Wall (in)'),ylabel('Temperature
(Fahrenheit)'),legend('Time 1','Time 2','Time 3','Time 4'),title('Trombe Wall
Temperatures'))
here's my code to get x and y
%We need a y for every plot time
%First find out how many plot times we need
[r,c]=size(Plot_Time);
%Then we create a zero matrix to house all the numbers
y=zeros(r,Nodes);
%Then we create a while loop to populate it
n=1;
while n<=r
y(n,:)=T(:,(Plot_Time(n)-Start_Time).*Hour_Step+1);
n=n+1;
end
%We need to get our variables assigned
x=linspace(0,Wall_Thickness,length(y(1,:)));
y ends up being a 4 by 41 matrix with the current data set x is a 1 by 41 with the current data set. I've double, triple and quadruple checked these matrices.
I also get the same error when I restrict y to one row and 41 columns
any ideas?
Thanks!!

채택된 답변

Matt Fig
Matt Fig 2012년 12월 3일
편집: Matt Fig 2012년 12월 3일
You are calling PLOT incorrectly. PLOT only takes the variables to be plotted and lineseries properties, not axes properties.
plot(x,y)
xlabel('Distance Through Wall (in)')
ylabel('Temperature (Fahrenheit)')
legend('Time 1','Time 2','Time 3','Time 4') % Child of figure
title('Trombe Wall Temperatures')
The title, xlabel and ylabel are properties of the axes that hold the handles to text objects. They are not lineseries properties. Even if they were, you would be calling them incorrectly the way you did. I suggest you read the documentation for PLOT:
doc plot
  댓글 수: 1
Paul
Paul 2012년 12월 3일
Thank you so much!! I've been using comma's all the way through the year forgot you closed the plot function and then you type commas. But I like your way much better, makes the code much more readable.
Thanks a ton!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 12월 3일
dbstop if error
Then inspect the size(of each variable).

Walter Roberson
Walter Roberson 2012년 12월 3일
plotting with y of size M x N (and M > 1), is treated as a request to draw N plots of M points each. Transpose your y so that you are plotting 41 x 4 to get 4 plots of 41 points each.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by