Plotting 3D Graph in Matlab

9 vues (au cours des 30 derniers jours)
Algorithms Analyst
Algorithms Analyst le 12 Sep 2013
Réponse apportée : BhaTTa le 11 Mar 2025
Hi all
I have got the statistics from 5 differenct algorithms and I want to plot them in 3D graph using matlab.How can I do that.I have statistics like that A=[88 85 83 80 70 64 58 53 50 45 41 40 34 33 30]; B=[55 58 61 63 65 67 69 71 73 76 79 81 84 86 89]; C=[78 73 69 66 62 59 56 54 51 47 44 42 38 36 33]; D=[50 53 55 57 59 61 63 65 66 68 69 71 72 73 75]; E=[89 86 84 81 71 65 60 55 52 47 42 41 35 35 31]; F=[45 51 52 53 55 56 58 61 63 65 66 68 69 70 70]; G=[71 69 68 68 66 64 65 63 61 59 57 56 54 53 52]; H=[38 39 42 43 45 46 47 49 51 52 53 55 56 57 57];
HOw can I plot them in matlab using 3D plot

Réponses (1)

BhaTTa
BhaTTa le 11 Mar 2025
Hey @Algorithms Analyst, To plot the statistics from multiple algorithms in a 3D graph using MATLAB, you can use the plot3 function. This function allows you to plot 3D lines or points by specifying X, Y, and Z coordinates. In this case, you can use the indices of your data as one axis (e.g., X-axis), and the values from each algorithm as the Y and Z axes.
Here's an example of how you can plot the given data:
% Define the data
A = [88 85 83 80 70 64 58 53 50 45 41 40 34 33 30];
B = [55 58 61 63 65 67 69 71 73 76 79 81 84 86 89];
C = [78 73 69 66 62 59 56 54 51 47 44 42 38 36 33];
D = [50 53 55 57 59 61 63 65 66 68 69 71 72 73 75];
E = [89 86 84 81 71 65 60 55 52 47 42 41 35 35 31];
F = [45 51 52 53 55 56 58 61 63 65 66 68 69 70 70];
G = [71 69 68 68 66 64 65 63 61 59 57 56 54 53 52];
H = [38 39 42 43 45 46 47 49 51 52 53 55 56 57 57];
% Define the X-axis as the index of each data point
X = 1:length(A);
% Create a new figure
figure;
% Plot each algorithm's data in 3D
plot3(X, A, ones(size(A)), 'r-o', 'DisplayName', 'Algorithm A');
hold on;
plot3(X, B, 2*ones(size(B)), 'g-o', 'DisplayName', 'Algorithm B');
plot3(X, C, 3*ones(size(C)), 'b-o', 'DisplayName', 'Algorithm C');
plot3(X, D, 4*ones(size(D)), 'k-o', 'DisplayName', 'Algorithm D');
plot3(X, E, 5*ones(size(E)), 'm-o', 'DisplayName', 'Algorithm E');
plot3(X, F, 6*ones(size(F)), 'c-o', 'DisplayName', 'Algorithm F');
plot3(X, G, 7*ones(size(G)), 'y-o', 'DisplayName', 'Algorithm G');
plot3(X, H, 8*ones(size(H)), 'r-o', 'DisplayName', 'Algorithm H'); % Changed to 'r' for red
% Customize the plot
xlabel('Index');
ylabel('Value');
zlabel('Algorithm');
title('3D Plot of Algorithm Statistics');
legend show;
grid on;
view(3); % Set the default 3D view
% Hold off to stop adding to the plot
hold off;

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by