I'm getting a plotting length mismatch error but my lengths match
조회 수: 2 (최근 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!!
댓글 수: 0
채택된 답변
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
추가 답변 (2개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!