How to plot a 3d plot (surf) from an XYZ table, X and Y coming from for loops?

I know this question is similar to almost all the questions on 3d plot, but I want to understand how I can improve my script ahead when writing the for loops. And later easily plot the surf plot.
I have this code (not I MWE, I give the output directly after:
for tau=1:2
for phi=0:25
fraconnect=sum(sum(phi))/25
%here I'm calling a function (not here) that integrates phi and tau
[t, m]=ode45(@Diff_con,[0 T],phi, tau)
nb=sum(sum(m));
prev=[prev; nb, tau, fraconnect]; %so here I'm not interested in getting phi out
end
end
and I get a real table that I'd like to turn into a surf plot:
prev=
1.0649 1 0.04
1.0018 1 0.08
1.0649 1 0.12
1.1463 1 0.16
1 1 0.2
1.1285 1 0.24
1.0827 1 0.28
1 1 0.32
1.258 1 0.36
1.3202 1 0.4
1.2086 1 0.44
1.5489 1 0.48
1.479 1 0.52
1.8405 1 0.56
1.9672 1 0.6
1.294 1 0.64
3.3 1 0.68
7.4016 1 0.72
5.9797 1 0.76
11.438 1 0.8
22.9 1 0.84
75.764 1 0.88
95.413 1 0.92
187.06 1 0.96
325.6 1 1
1 2 0.04
1 2 0.08
1.5709 2 0.12
1.2779 2 0.16
1.257 2 0.2
1 2 0.24
1.9758 2 0.28
10.729 2 0.32
6.5317 2 0.36
166.99 2 0.4
222.71 2 0.44
13.212 2 0.48
609.52 2 0.52
819.03 2 0.56
1174.8 2 0.6
1234.7 2 0.64
1403.5 2 0.68
1494.2 2 0.72
1459 2 0.76
1649.3 2 0.8
1784.2 2 0.84
1865.8 2 0.88
1979.3 2 0.92
2074.3 2 0.96
2166.2 2 1

 Réponse acceptée

hibou, use
X = reshape(prev(:,1),[],2);
Y = reshape(prev(:,2),[],2);
Z = reshape(prev(:,3),[],2);
surf(X,Y,Z)

1 commentaire

Thanks! That's exactly what I wanted ! the solution with griddata was also pretty cool but basically I wanted to understand what surf needed ! Great !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by