Using surf function to plot slices of a 3D matrix

Click For Summary
SUMMARY

The discussion focuses on using the "surf" function in MATLAB to visualize 2D slices of a 3D matrix, specifically a 100x100x100 matrix named "A". The user encountered an error when attempting to plot slices along the first dimension, which required a workaround. The solution provided involves using the "squeeze" function to convert the 1x100x100 array into a 100x100 array, enabling successful plotting with "surf".

PREREQUISITES
  • Understanding of MATLAB programming environment
  • Familiarity with 3D matrix manipulation
  • Knowledge of the "surf" function for surface plotting
  • Experience with the "squeeze" function in MATLAB
NEXT STEPS
  • Explore advanced visualization techniques in MATLAB using "surf" and "meshgrid"
  • Learn about 3D matrix operations and their applications in data analysis
  • Investigate other MATLAB functions for slicing and visualizing multidimensional arrays
  • Study performance optimization techniques for large matrix operations in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers who need to visualize multidimensional data effectively, particularly those working with 3D matrices and surface plots.

mikeph
Messages
1,229
Reaction score
18
Using "surf" function to plot slices of a 3D matrix

Hello

I have a 100x100x100 matrix called "A" and want to plot 2D slices of it to get a feel of where the global minima are (since there is no other way which I know of visualising it... is there?)

If I take a slice of the third component, eg. "surf(A(:,:,50))" it will plot it fine, but I cannot do this for the other two:

Code:
>>> surf(A(1,:,:))
? Error using ==> surf at 74
Z must be a matrix, not a scalar or vector.

Is there a simple workaround for this?

Thanks
 
Physics news on Phys.org


Use surf(squeeze(A(1,:,:))). Squeeze will turn the 1 x 100 x 100 array into a 100 x 100 array.
 


Brilliant- thanks very much!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
2
Views
3K