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

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by