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

4 次查看(过去 30 天)
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 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by