I am having a problem plotting a 2D array via Plot3 function. How can I use the Rows and Columns as my X and Z axis?

1 view (last 30 days)
I am having trouble using the Plot3 function.
I have a 2D array that I would like to plot in 3D by the dimensions of the Row # X value, Column # as my Z value and the actual cell values as my Y value.
The problem I'm having is that the input variables must all be the same size. This seems like it should be a pretty straight forward problem, but I haven't found any documentation or work around for this.
Here is the code I've written so far for this routine.
[rows,columns] = size(emg_recording)
ArrayX=(1:rows)' ArrayZ=(1:columns)'
Plot3(emg_recording)
Any help would be greatly appreciated.

Answers (1)

Star Strider
Star Strider on 13 Oct 2015
You have to create three column vectors from your data to use them with plot3, and they all have to be equal length. This replicates the row and column sizes to be equal to the number of elements in the array, and plots them. That’s the only way I can think of to do what you describe. It has the virtue of running, but I have no idea if it does what you want:
emg_recording = randi(9,6,8);
X = repmat([1:size(emg_recording,1)]', size(emg_recording,2), 1);
Z = repmat([1:size(emg_recording,2)]', size(emg_recording,1), 1);
Y = emg_recording(:);
figure(1)
plot3(X, Y, Z)
grid on
xlabel('Rows')
ylabel('Cell Value')
zlabel('Columns')

Community Treasure Hunt

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

Start Hunting!