필터 지우기
필터 지우기

Is there a way to plot multiple files using a loop in matlab?

조회 수: 4 (최근 30일)
Brandon Bush
Brandon Bush 2018년 7월 19일
댓글: Brandon Bush 2018년 7월 19일
I want to use a for loop to plot data from a range of files whos names are string values. This is the code I am using:
%Convert variable year from integer to string
yr=num2str(17);
dy=num2str(15);
mn=num2str(3);
yr2 = num2str(17);
dy2 = num2str(4);
mn2 = num2str(4);
%Create a MMDDYY string
date_str=[mn '-' dy '-' yr];
date_str2=[mn2 '-' dy2 '-' yr2];
for i = date_str:date_str2
is there a way I can plot the data from 3-15-17 to 4-4-17, which are in excel files? I already have programs in which I can plot an individual day, I just want to be able to plot a range of days.

채택된 답변

Jason Whitfield
Jason Whitfield 2018년 7월 19일
Instead of manually creating date strings, try using the datetime object. It can be iterated like you want, and then you can create a string representing the filename using the datestr function.
  댓글 수: 3
Jason Whitfield
Jason Whitfield 2018년 7월 19일
Is there any particular reason you can't use datetime? The following code seems to accomplish what you're looking for:
for day = datetime(17, 3, 15):datetime(17, 4, 4)
disp(datestr(day, 'mm-dd-yy'));
end
Brandon Bush
Brandon Bush 2018년 7월 19일
It was saying that the input must be a matrix with three or six columns but I mightve just been putting in the data wrong

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by