4D plot - Radiation pattern
3 次查看(过去 30 天)
显示 更早的评论
Dear Community,
I have to create a 4D Plot. It has to be something like this: https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/9519/versions/9/screenshot.jpg
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
0 个评论
回答(1 个)
Cam Salzberger
2017-5-15
编辑:Cam Salzberger
2017-5-15
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.
Alternatively, you could just "meshgrid" the x, y, and z values, then plot colored points with "plot3".
-Cam
5 个评论
Cam Salzberger
2017-5-18
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!