Unable to Plot in For Loop
1 回表示 (過去 30 日間)
古いコメントを表示
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
2018 年 8 月 3 日
I tried this in R2018a.
TempFile(:,5) % value = 'r'.
What does parsing 'r' in hour function mean?
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!