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

10 ビュー (過去 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).
  1 件のコメント
Paul
Paul 2012 年 12 月 3 日
I did this several times already.
size(x) 1 41
size(y) 4 41

サインインしてコメントする。


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 Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by