필터 지우기
필터 지우기

make a contour plot with dates on x axis, time on y axis and fog concentration as z values.

조회 수: 35 (최근 30일)
I need to make a contour plot based on the calculated total fog. I am unable to do so as I am new to MATLAB. Hope Someone can help me.For reference I am attaching a sample of my data. Thanks
  댓글 수: 4
dpb
dpb 2018년 9월 28일
Will need to use NaN to infill I think to get a regular grid; I imported the file as table to 'spearmint some.
contour may also require using datenum rather than datetime for the date/time axes; it is one of the specialty plotting routines not yet (R2017b) gotten to with aliased version for the new class.
Toni
Toni 2023년 3월 13일
For contour plots, x and y axis ticks labels can be modifed via xticklabels and yticklabels. Reshape in the answer below did not work due to missing data, but code below avoids that by inserting Nan where data is missing.
filename = '1st-10th_dec.csv'
data=readtable(filename)
data.Date = datetime(data.Date,'inputformat','dd-MM-yyyy');
data.Time = duration(data.Time,'inputformat','hh:mm');
date = unique(data.Date);
t = unique(data.Time);
for i=1:length(date)
for j=1:length(t)
index = find(data.Date == date(i) & data.Time == t(j));
if ~isempty(index)
v(j,i) = data.Fog___(index);
else
v(j,i) = NaN;
end
end
end
figure
contourf(datenum(date),datenum(t),v)
xticks(datenum(date))
xticklabels(string(date))
t_ticks = [min(t):hours(2):max(t)];
yticks(datenum(t_ticks))
yticklabels(string(t_ticks))

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

채택된 답변

jonas
jonas 2018년 9월 28일
편집: jonas 2018년 9월 28일
As dbp said, contour is not compatible with datetime format. Here's an example with surf, which is quite similar.
data=readtable('1st-10th_dec.csv')
date=datetime(data{:,1},'inputformat','dd-MM-yyyy');
t=duration(data{:,2},'inputformat','hh:mm');
v=data{:,3};
[~,udate]=findgroups(date);
[~,ut]=findgroups(t);
v=reshape(v,numel(ut),numel(udate))
surf(udate,ut,v)
view([0 90])
and here is the example with contour,
data=readtable('1st-10th_dec.csv')
v=data{:,3};
date=nan(size(data,1),1)
t=nan(size(data,1),1)
date(~isnan(v))=datenum(data{~isnan(v),1},'dd-mm-yyyy')
t(~isnan(v))=datenum(data{~isnan(v),2},'HH:MM')
[~,udate]=findgroups(date);
[~,ut]=findgroups(t);
v=reshape(v,numel(ut),numel(udate))
contour(udate,ut,v)
datetick('x','dd/mm','keeplimits','keepticks')
datetick('y','hh:mm','keeplimits','keepticks')
The resulting plot is quite ugly. This is however easy to fix by interpolation.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by