0
votes

I'm trying to create a 3D plot in Matlab of a structure element, Bstruct.scen_1. In this structure, each row is a year, each column is a distance, and the cell value is a population size (so for example, row 3, column 7 would yield the number of adults in year 3 at 7 km.) I want the X-axis to be the number of columns in Bstruct.scen_1, the Y-axis to be the actual value in the cell at (X,Z), and the Z-axis to be the number of rows in Bstruct.scen_1.

Conceptually, what I'd like to accomplish is:

plot3(Bstruct.scen_1(1:num_cols), Bstruct.scen_1(cellvalue), Bstruct.scen_1(1:num_rows))

I'm struggling with the syntax of structures and would really appreciate help in plotting both the elements and the dimensions of this structure. (I mostly code in R with 'tidy' data.) Thank you!

1

1 Answers

1
votes

The value of a structure field can be any data type. It sounds like the scen_1 field contains a 2D matrix. The plot3 function expects an X, Y, and Z coordinate for each data point. In your case, if you're wanting to plot the value of the matrix at each 2D location, using the function surf (or mesh) might provide a good start:

% random data for demonstration
Bstruct.scen_1 = rand(20, 10);

figure;
surf(Bstruct.scen_1);