I'm getting a plotting length mismatch error but my lengths match
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Matt Fig
el 3 de Dic. de 2012
Editada: Matt Fig
el 3 de Dic. de 2012
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
Más respuestas (2)
Walter Roberson
el 3 de Dic. de 2012
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 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!