Surf 3D Matrix size issue

Hello everyone,
currently i try to understand some code i got from my supervisor in college. My task is to create a 3D plot. I've got vector V.x with dimension 1x41 and a vector V.y with dimension 1x41 as well. Besides that i got a 3D Matrix E with the dimension 41x41x301.
I tried to use surf(V.x,V.y,E).
I get an error because of the dimensions must agree.
Where is the Problem? Is it because of the "x301", because E is a 3D Matrix?
If so, how can i fix it?
Sincerely
Lucas

 Risposta accettata

Ameer Hamza
Ameer Hamza il 4 Mag 2020
Yes, It is because of 3D array. Are you trying to create 301 surfaces? You can plot a single surface like this
surf(V.x, V.y, E(:,:,1))
To plot all 301 surfaces on single axes, use for loop
n = size(E,3);
figure;
ax = axes();
hold(ax)
for i=1:n
surf(V.x, V.y, E(:,:,i));
end

3 Commenti

Lucas Junghans
Lucas Junghans il 5 Mag 2020
Modificato: Lucas Junghans il 5 Mag 2020
Thanks for the answer.
Well do be honest im still not quite sure how this all should work.
My supervisor told me that i should try to get a plot.
I guess firstly you probably need some more Information. So I've got the vector V.x which are just some x - values the same with V.y, but E is the Electric Field and therefor kind of like the intensity of light, since I ~ |E|^2 .
What i should try is to get a plot, where x = x values, y = y values , z = the Intensity (|E|^2) and the color should be the phase of E. But would it not be a 4D plot? Im still kind of new to Matlab, by the way.
And is it possible to still use surf? i thought i could use surf(X,Y,Z,C) with C = color = the Phase.
hopefully my problem is understandable :)
Best greetings
Lucas
Edit: Oh and i forgot to mention, that my E has complex values.
Ok. I guess i just solved my problem thanks to your answer :)
So thanks again.
n = size(E,3);
ax = axes();
hold(ax)
for i=1:n
surf(V.x, V.y, abs(squeeze(E(:,:,i).^2)),angle(squeeze(E(:,:,i).^2)));
end
Ameer Hamza
Ameer Hamza il 5 Mag 2020
I am glad to be of help.
Yes. You can use surf to display a 4th-dimensional value on a surface.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Prodotti

Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by