Borrar filtros
Borrar filtros

Unable to Plot in For Loop

6 visualizaciones (últimos 30 días)
Cameron Power
Cameron Power el 20 de Jul. de 2018
Respondida: Steven Lord el 3 de Ag. de 2018
I am trying to make a two y-axis plot in a for loop using the code below:
t = 10;
for n = 1:t
TempFile = sprintf('%s%d', 'ShearEnv_top', n);
m = hour(TempFile(:,5));
plot(m, TempFile(:,12) .* 10, 'b-'), ylim([0 360]), grid minor, ylabel('Wind Direction (degrees)'), xlabel('Time of Day(Hr)'), title('Daily Wind Direction Patterns');
yyaxis right, plot(m, TempFile(:,14) ./ 3.6, 'g-')
end
However when I run it I get the error;
"Error using plot
Invalid first data argument.
Error in Keep_3 (line 8)
plot(TempFile(:,5), TempFile(:,12) .* 10, 'b-'), ylim([0 360]), grid minor, ylabel('Wind Direction (degrees)'), xlabel('Time of Day(Hr)'), title('Daily Wind Direction Patterns');'
I`ve tried using the hour function but I either get an error when using brace brackets for;
Or an error that the input is of type 'char'
t = 10;
for n = 1:t
TempFile = sprintf('%s%d', 'ShearEnv_top', n);
m = hour(TempFile(:,5));
plot(m, TempFile(:,12) .* 10, 'b-')
ylim([0 360]), grid minor
ylabel('Wind Direction (degrees)'), xlabel('Time of Day(Hr)'), title('Daily Wind Direction Patterns');
yyaxis right, plot(m, TempFile(:,14) ./ 3.6, 'g-')
end
"Undefined function 'hour' for input arguments of type 'char'.
Error in Keep_3 (line 8)
m = hour(TempFile(:,5));"
I have made plots in Matlab R2017a with this code but in Matlab R2018a these errors arise.
  1 comentario
Viren Gupta
Viren Gupta el 3 de Ag. de 2018
I tried this in R2018a.
TempFile(:,5) % value = 'r'.
What does parsing 'r' in hour function mean?

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 3 de Ag. de 2018
It looks like TempFile is the name of a file that you want to read into MATLAB, but you skipped the actual file reading step.
Alternately, it could be the name of a variable (one in a series of sequentially named variables) that you want to use, but if that's the case you shouldn't do that. Use the alternative approaches described on that page instead.

Categorías

Más información sobre Modeling and Prediction en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by