필터 지우기
필터 지우기

Unable to Plot in For Loop

조회 수: 6 (최근 30일)
Cameron Power
Cameron Power 2018년 7월 20일
답변: Steven Lord 2018년 8월 3일
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