フィルターのクリア

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 Center および File Exchange2-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