Azzera filtri
Azzera filtri

Unable to Plot in For Loop

6 visualizzazioni (ultimi 30 giorni)
Cameron Power
Cameron Power il 20 Lug 2018
Risposto: Steven Lord il 3 Ago 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 Commento
Viren Gupta
Viren Gupta il 3 Ago 2018
I tried this in R2018a.
TempFile(:,5) % value = 'r'.
What does parsing 'r' in hour function mean?

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 3 Ago 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.

Community Treasure Hunt

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

Start Hunting!

Translated by