How to draw a graph with a colormap from a txt file?

9 ビュー (過去 30 日間)
PARIVASH PARIDAD
PARIVASH PARIDAD 2018 年 10 月 9 日
コメント済み: PARIVASH PARIDAD 2018 年 10 月 11 日
I have a txt file consisting of 10 columns. The first 3 columns are year/month/day and the next 7 columns are my moisture data in 7 different depths. (this data set is for 3 years) 2014 1 1 10.2 13.4 14 15.1 17 . . . 2017 12 30 12.4 14 15.6 17 19.4
I wrote a code to plot a graph using datenume and plot function and it look likes image1. It is correct but now I am asked to make the same graph in the format of image2. I dont know what function draws a graph like image2 from my data set. Can anyone help me? Thanks

採用された回答

jonas
jonas 2018 年 10 月 9 日
編集済み: jonas 2018 年 10 月 10 日
You can do that with e.g. surf or contourf . I would suggest surf because it works with datetime format, which you should use instead of datenum.
Here's a code adapted to your data
% Load data
data=xlsread('Soil misture.xlsx')
% Save depths, d, and remove this row
d=data(1,~isnan(data(1,:)));
data(1,:)=[];
% Save times, t, as datetime format
t=datetime(data(:,1),data(:,2),data(:,3));
% Save moisture content, u, as 2d matrix
u = data(:,4:end);
% Interpolate over time
ti = t(1):days(1):t(end);
ui = interp1(t,u,ti);
% Interpolate over depth
di = min(d):1:max(d);
uii = interp1(d,ui',di);
% plot
surf(ti,di,uii,'edgecolor','interp');
% some aestethics
ax=gca;
axis tight
view([0 90]);
cb = colorbar(gca,'location','southoutside');
cb.Label.String = 'Soil water content (cm^3/cm^3)';
ylabel('Soil depth (cm)');
xlabel('Time','fontweight','bold');
xtickformat('yyyy/MM/dd');
ax.XRuler.TickLabelRotation = 40;
ax.XRuler.TickDirection = 'out';
ax.YRuler.TickDirection = 'out';
ax.Layer = 'top';
ax.Color = 'none';
grid off
colormap(jet(20))
  17 件のコメント
jonas
jonas 2018 年 10 月 10 日
Attached is an updated script. The function I linked before was quite annoying, so I used another one. Here is the link . Download it, unzip and put the .m-file in the in the MATLAB search path, for example the same folder as your script, and then execute the attached script. I'm fairly sure it will work without additional issues.
You should take a look at the Getting started with MATLAB links. This forum is great, but you need to be able to do some basic coding yourself.
PARIVASH PARIDAD
PARIVASH PARIDAD 2018 年 10 月 11 日
Thanks so much Jonas. I will take your advice and read it. Thanks again.

サインインしてコメントする。

その他の回答 (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