Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

jonas
jonas il 9 Ott 2018
Modificato: jonas il 10 Ott 2018
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 Commenti
jonas
jonas il 10 Ott 2018
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 il 11 Ott 2018
Thanks so much Jonas. I will take your advice and read it. Thanks again.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by