How can I plot three columns of a dataset to produce an image or a map?

4 次查看(过去 30 天)
I have the randomly generated data with the final dataset in the Variable 'DATA'
===========================================
D = [66;67;68;69;70;74;75;76;78;83];
Day =repelem(D,11);
timeH = (13:23)'; timeH = repmat(timeH,[10,1]);
xmin=0;
xmax=0.9;
n=110;
x = xmin+rand(1,n)*(xmax-xmin);
x = x';
DATA = [Day,timeH,x];
===========================================
I want to produce an image or map with x-axis Day, y-axis as timeH and z-axis as x.
I have tried with:
imagesc(Day,timeH, x)
but the output I'm getting is more of stripped color lines,
I want a map like the images attached (days on the x axis instead)
or
I would be grateful if i can get help. Thank you

采纳的回答

Joe Vinciguerra
Joe Vinciguerra 2023-3-24
The data needs to be reshaped.
Here are a few different plotting options, depending no how you went to represent the data.
D = [66;67;68;69;70;74;75;76;78;83];
Day =repelem(D,11);
timeH = (13:23)'; timeH = repmat(timeH,[10,1]);
xmin=0;
xmax=0.9;
n=110;
x = xmin+rand(1,n)*(xmax-xmin);
x = x';
DATA = [Day, timeH, x];
% Reshape the data into matrices
d = reshape(DATA(:,1), [11, 10]);
t = reshape(DATA(:,2), [11, 10]);
X = reshape(DATA(:,3), [11, 10]);
% plot as a scaled color image
imagesc(Day, timeH, X)
colorbar()
% plot as a scaled color image with interpolated visualization
imagesc(Day, timeH, X, "Interpolation", "bilinear")
colorbar()
% plot as a filled contour map
contourf(d, t, X, "LineStyle","none")
colorbar()
% plot as a 3D surface, viewed from top with interpolated shadind
surf(d, t, X, "LineStyle","none")
shading(gca, "interp")
colorbar()
view(0, 90)
axis tight
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by