Unable to Plot in For Loop

6 次查看(过去 30 天)
Cameron Power
Cameron Power 2018-7-20
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 个评论
Viren Gupta
Viren Gupta 2018-8-3
I tried this in R2018a.
TempFile(:,5) % value = 'r'.
What does parsing 'r' in hour function mean?

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2018-8-3
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.

类别

Help CenterFile Exchange 中查找有关 Modeling and Prediction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by