4D plot - Radiation pattern

Dear Community,
I created an matrix in x, y direction and also in z direction- This 3 are my frist values. The fourth values is the quantity of reads per point in the matrix.
I tried to create an code but I failed. The Problem is that the z value is only in 3 steps not in 21 steps like the other x and y direction.
You can find my code in the appendix.
My commande window on matlab tells me that ther is a issue with the z data: *Error using surf (line 82) Z must be a matrix, not a scalar or vector.
Error in test (line 80) surf(x,y,z,values) *
I would be very happy if you can help me to solve my problem
Reagards Süleyman

Respuestas (1)

Cam Salzberger
Cam Salzberger el 15 de Mayo de 2017
Editada: Cam Salzberger el 15 de Mayo de 2017

1 voto

Hello Süleyman,
I think there's a slight misunderstanding happening here. "surf" doesn't quite produce a 4-D plot. It's a 3-D surface, with the possibility of customizing the color of that surface. From my understanding of your code, it looks like you have three separate planes in the z-dimension, each of which has values which you would like to display as colors.
For this, I would recommend three separate calls to "surf", one for each plane, with the corresponding layer of "values". You'll need to specify the "Z" input to surf as a matrix of equal size to one of the layers of "values", but all the same value of "z", to make this flat plane.
Also, I believe that the "values" matrix definition will need to be changed. Currently it comes out as 63x21, when I think you want 21x21x3.
Try defining it using either "cat", or just one layer at a time (z(:,:,1) = ...).
Alternatively, you could just "meshgrid" the x, y, and z values, then plot colored points with "plot3".
-Cam

5 comentarios

Süleyman Köken
Süleyman Köken el 15 de Mayo de 2017
Hey Cam,
first of all I would like to say thank you for your quick response.
Yes you're right. I have three sepearte planes in the z-dimension and each of has values which I would like to display as colors.
And I agree with that. I have to seperate the values matrix. I noticed that It seems like 63x21 but I want the format of 21x21x3.
After that, I have to plot also an diagram with 21x21x21 Matrix. I guess this will be easier to create. But also here I have to sepearte it and I dont know how.
The problem is, that I am a totaly new in Matlab and I have no idea about the syntax. But I can see that you have a great experience and you understand my problem.
I know that it seems maybe like a lot of work to explain me that, but if you would help me, I'm sure, the universe will be good to you in the future :-D
Cam Salzberger
Cam Salzberger el 15 de Mayo de 2017
So the separating out the layers of "values" is simple. If you're defining them all in code, just do something like:
values = cat(3,[1 2 ; 3 4],[5 6 ; 7 8],[9 10 ; 11 12]);
Except with your 21x21 matrices as each input, rather than my example ones there.
Then just loop through each layer and plot the surface with something like:
figure
axes
hold on
for k = 1:size(values,3)
surf(x,y,z(k)*ones(size(values,1),size(values,2)),values(:,:,k))
end
I haven't tested that code, but I think it should be close. The 21x21x21 matrix, assuming you want the same kind of plot, should probably work the same way.
Also, if you want the surface to look more similar to the example you linked, you can just set the EdgeColor and FaceColor properties of the surface plot:
surf(...,'EdgeColor','none','FaceColor','interp')
Süleyman Köken
Süleyman Köken el 18 de Mayo de 2017
I tried a new code, but unfortunately it doesn't work. you can find it also in the appendix
Cam Salzberger
Cam Salzberger el 18 de Mayo de 2017
When you put the code into the Editor, always check any of the Code Analyzer warnings or errors. This will give you clues as to what's going on.
Now I'm not sure if it's the whole going through MATLAB Answers thing, but you can't have that many spaces when creating matrices. Newlines, at the very least, do matter in MATLAB. So instead of:
cat(3,
[
3 4 ;
5 6 ;
]
,
[
blah blah...
Try putting everything a bit closer together.
You have the other surf statement in the loop, so I don't know why you left "surf(x,y,z)" in there.
"valueslabel" is not a built-in function, nor is it defined in the file, so that had to go for me.
I didn't mean to use this code literally:
surf(...,'EdgeColor','none','FaceColor','interp')
What I meant was for any call to "surf", you could add in some Name-Value pair arguments at the end to turn off edges and make the shading more interpolated. For example:
surf(x,y,z(k)*ones(size(values,1),size(values,2)),values(:,:,k),'EdgeColor','none','FaceColor','interp')
Also may want to throw a:
view(3)
at the end to make it automatically view the surfaces from a 3-D perspective. When I do all this, it works for me.
Süleyman Köken
Süleyman Köken el 25 de Mayo de 2017
Hey Dude,
I want to thank you. It was really nice that you helped me a lot. Im appreciated. Now I want to split every level into an 2D plot. I tried something. You can find it also in the Appendix. I see, something is missing there because it opens the window for the plot but its blank.
I would be really happy if you can help me
Greetings Süleyman

Iniciar sesión para comentar.

Preguntada:

el 15 de Mayo de 2017

Comentada:

el 25 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by