- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
How can I create a 3D mesh/surface chart with one matrix of data
4 views (last 30 days)
Show older comments
Dear All, I am trying to convert the following simple code into a mesh or surface because at the moment I am only able to plot the single vectors of the matrix I have. I am pasting below a simple example where the first column is a column with dates and the other vectors contain the datapoints (my matrix is larger than this but the inciple stays the same)
T = [2001 3 5 7;
2002 4 6 7;
2003 8 10 11;
2004 7 13 7;
2005 4 15 12;
2006 2 16 10] %example of matrix where the first column contains the dates
a = T(:,1) %extract the 4 vectors that compose the matrix
b = T(:,2)
c = T(:,3)
d = T(:,4)
x = zeros(size(a))
x1 = ones(size(a))
x2 = x1 * 2
plot3(x, a, b); %plotting 3 vectors in a 3D chart where y-axis contains the dates, x-axis is a scalar %equalling to the number of to chart (i.e. 3 in this case, excluding the initial column with dates)
hold on;
plot3(x1,a,c);
hold on;
plot3(x2,a,d);
hold off;
0 Comments
Answers (1)
Hassaan
on 23 Jan 2024
% Example matrix
T = [2001 3 5 7;
2002 4 6 7;
2003 8 10 11;
2004 7 13 7;
2005 4 15 12;
2006 2 16 10]; % Matrix where the first column contains the dates
% Extract the data
dates = T(:,1); % Dates
data = T(:,2:end); % Data points
% Create a grid for plotting
[X, Y] = meshgrid(1:size(data,2), dates);
% Plotting as a mesh
figure;
mesh(X, Y, data);
xlabel('Data Series');
ylabel('Year');
zlabel('Values');
title('Mesh Plot');
% Plotting as a surface
figure;
surf(X, Y, data);
xlabel('Data Series');
ylabel('Year');
zlabel('Values');
title('Surface Plot');
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
Feel free to contact me.
2 Comments
Hassaan
on 23 Jan 2024
You are welcome.
----------------------------------------------------------------------------------------------------------------------------------------------------- If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests: Technical Services and Consulting Embedded Systems | Firmware Developement | Simulations Electrical and Electronics Engineering
Feel free to contact me.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
