Plot 2 matrices in one graph with 3 axis
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
kortas manel
il 16 Giu 2018
Commentato: Ameer Hamza
il 16 Giu 2018
Hi, I have to plot curves "MSE" witch depend on 2 variables. Variable 1 : "pct=1:1:n" and variable 2 : "CR" .
But "CR" depends on two variables also:
"ptx=1:1:n" and "pct=1:1:n"
MSE=fct(CR,pct)
Here a simplification of the code:
for pct=1:1:n
for ptx=1:1:n
calculate CR(pct,ptx)
calculate MSE(pct,ptx)
end
end
I want to plot curves of "MSE" in function with "pct" and "CR" , it means ;
axis x : "pct"
axis y : "CR"
axis z : "MSE"
That is, a kind of succession of curves Thank you in advance
4 Commenti
Ameer Hamza
il 16 Giu 2018
Your x variable is an n-element vector, whereas y and z are nxn matrices. And from your for loop example, it seems that you want several 2D plots. Can you show an example plot similar to what you are trying to draw?
Risposta accettata
Ameer Hamza
il 16 Giu 2018
Modificato: Ameer Hamza
il 16 Giu 2018
From your question description, it appears you want something like this
Here is a sample code with random values to generate this
n = 10;
x = 1:n; % 1 x n vector
y = repmat(1:n, n, 1); % n x n matrix
z = rand(n); % n x n matrix
plot3(1*ones(n,1), y(1, :), z(1, :)); % plot one line outside for loop to get the axes handle
ax = gca;
hold(ax);
grid on
xlabel('pct');
ylabel('CR');
zlabel('MSE');
for i=2:n
plot3(i*ones(n,1), y(i, :), z(i, :));
end
2 Commenti
Ameer Hamza
il 16 Giu 2018
In that case, you will also need to adjust the first input to plot3()
plot3(i*ones(9,1), y(i, :), z(i, :));
I guess this might be causing the issue.
Più risposte (1)
Guillaume
il 16 Giu 2018
If your calculate functions can operate on matrices:
[pct, ptx] = ndgrid(n);
CR = yourcalculateCRfunction(pct, ptx);
MSE = yourcalculateMSEfunction(pct, ptx);
plot3(pct, CR, MSE);
Otherwise
[pct, ptx] = ndgrid(n);
CR = zeros(size(pct));
MSE = zeros(size(pct));
for i = 1:numel(pct)
CR(i) = yourcalculateCRfunction(pct(i), ptx(i));
MSE(i) = yourcalculateMSEfunction(pct(i), ptx(i));
end
plot3(pct, CR, MSE);
0 Commenti
Vedere anche
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!