WHY CAN'T I PLOT THIS WITH "DATETIME"?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello everyone,
I can't plot because of the error with "data time".
Does anyone know how I can solve this problem.
Thank you.
채택된 답변
Star Strider
2021년 7월 20일
The first column is not a valid datetime array. It first needs to be converted to one.
Try this —
LD = load('LARSEN_MMEQ1.mat');
LARSENMMEQ1 = LD.LARSENMMEQ1;
LARSENMMEQ1.Var1 = datetime(LARSENMMEQ1.Var1, 'InputFormat','MM/dd/yyyy');
x = LARSENMMEQ1.Var1;
y = LARSENMMEQ1.Var2;
figure
plot(x, y)
grid
producing —

.
댓글 수: 8
Thank you.
But why do I get a line if I try to do this multiplication?
NEW=LARSENMMEQ1.Var2*10*0.35;

I have no idea. It works correctlly foir me —
LD = load('LARSEN_MMEQ1.mat');
LARSENMMEQ1 = LD.LARSENMMEQ1;
LARSENMMEQ1.Var1 = datetime(LARSENMMEQ1.Var1, 'InputFormat','MM/dd/yyyy');
x = LARSENMMEQ1.Var1;
y = LARSENMMEQ1.Var2*10*0.35;
figure
plot(x, y)
grid

So I guess the question is what exactrly are you plotting?
Note — In the plot you posted in your Comment the independent variable is obviously not the datetime variable, so it may be that you are plotting 'NEW' as a funciton of ‘Var2’ (or the reverse of that). They would be linearly related, with an intercept of 0 and a slope of 3.5 (or the inverse of that).
.
Thank you for your help!
But I can't get why the error still occurs:
"Unable to convert the text to datetime using the format 'dd/MM/yyyy'."
I also tried with those attached (that are similar) and it doesn't work.
My pleasure!
Of course the previous datetime import and conversion will not work, because the format is entirely different!
Try this —
LD = load('PAOLA_MMEQ1.mat');
PAOLAMMEQ = LD.PAOLAMMEQ;
dv = regexp(PAOLAMMEQ.Var1, '\d*\-\w*\-\d*','match');
PAOLAMMEQ.Var1 = datetime([dv{:}], 'InputFormat',"dd-MMM-yyyy").';
x = PAOLAMMEQ.Var1;
y = PAOLAMMEQ.Var2;
figure
plot(x, y)
grid

If you want to interpolate the missing data, use the fillmissing function, since there are 3008 NaN values in ‘y’. There are some anomalous values in Sep and Oct 2016, so you will have to decide on how to deal with them, so filloutliers and related functions are worth considering as well.
.
Pul
2021년 7월 21일
Thank you very much for your help and explanation.
Just a quick clarification: I can only see NaN values in September and October 2016; so what kind of anomalous values do you mean?
My pleasure.
There are no missing ‘x’ (datetime) values, so changing the plot to:
ym = ismissing(y);
yf = fillmissing(y,'linear');
figure
hpm = plot(x(ym), yf(ym), '.r', 'MarkerSize',3);
hold on
hpd = plot(x, y, '.-b');
hold off
grid
legend([hpd,hpm],'Data','Missing', 'Location','best')
shows the ‘y’ data in blue and all 3008 missing NaN values in red —

The anomalous values are the descending ‘spike’ in Sep-Oct 2016.
.
Pul
2021년 7월 21일
Thank you very much.
You've been very kind.
Star Strider
2021년 7월 21일
As always, my pleasure!
.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
