Plotting a multi-dimensional matrix

9 views (last 30 days)
Maheen Khan
Maheen Khan on 6 Aug 2022
Answered: Steven Lord on 6 Aug 2022
I want to plot a matrix from (353:411) rows and (424:499) columns across all the pages of the matrix. Is there any way to do that other than using plot as it is giving us error that "cannot plot three elements".
  7 Comments
Maheen Khan
Maheen Khan on 6 Aug 2022
i want to get a matrix out of my multi dimensional matrix of 480x720x1230 that contain the values from row 353 to 411 and columns 424 to 499 across all the 1230 frames and plot it with the values of matrix on y-axis and number of frames on x-axis

Sign in to comment.

Answers (2)

Cris LaPierre
Cris LaPierre on 6 Aug 2022
Edited: Cris LaPierre on 6 Aug 2022
If you want to create a 2D line plot where there is a different line (data series) for each sheet of your array, the simplest way I can think of is to reshape the data so that all the data for a given sheet is in a column. This would be your x values per your earlier description. For y, you would create a vector from 1:1230. Then you would just do plot(x,y).
From the plot documentation page: If all the sets share the same x- or y-coordinates, specify the shared coordinates as a vector and the other coordinates as a matrix. The length of the vector must match one of the dimensions of the matrix.
Here's an example using randomly generated data.
A = rand(480,720,1230);
% extract data
data= A((353:411),(424:499),:);
% create x by reshaping data into 4484x1230 array
x = reshape(data,[],size(data,3));
% Create y to correspond to sheet number
y = 1:size(data,3);
plot(x,y)

Steven Lord
Steven Lord on 6 Aug 2022
In MATLAB select the Plots tab on the Toolstrip. Click the small downward pointing triangle to the right side of the Plots section of that tab. Look at the small thumbnail pictures and take a look at the documentation for the function name below the one that looks close to the picture you want to create. That should include an example that you can use as a starting point for creating your own plot.
If none of them look like what you want to create, post a link to a picture showing us what you want to see. Just saying "I want a plot" is like saying "I want to eat" -- we can't make you food without knowing whether you want cereal, toast, a sandwich, a steak, curry, etc.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by