MATLAB Answers

Appropriate way to store 3d matrix ?

11 views (last 30 days)
Teerapong Poltue
Teerapong Poltue on 18 Jan 2021
Edited: Teerapong Poltue on 19 Jan 2021
I'm using
unitcellsize = 1:0.01:1.01;
num = max(size(unitcellsize));
for jj = 1:num
a{jj} = -unitcellsize(jj)/2:0.04:unitcellsize(jj)/2;
b{jj} = -unitcellsize(jj)/2:0.04:unitcellsize(jj)/2;
c{jj} = -unitcellsize(jj)/2:0.04:unitcellsize(jj)/2;
[X{jj},Y{jj},Z{jj}] = meshgrid(a,b,c);
end
Is this an appropriate way to store 3d matrix. I would like to store 3d matrix __x__x__.
If this is the appreciate way, how can I recall 3d matrix for using ?
  1 Comment
Bob Thompson
Bob Thompson on 18 Jan 2021
A 3D matrix is created, and data stored, simply by calling out a third dimension:
A = randi(100, 5, 4, 10); % Creates random integer matrix of size 5x4x10
This format works for pretty much any multidimesional matrix generation command (zeros, ones, rand), and assigning specific values just means calling out a third dimensional index value.
A(1,1,1) = 100; % Set first value to 100
A(:,1,1) = 100; % Set first column, first sheet to 100
I'm not sure how this applies to your data though, because all of the variables you've specified seem to just be row matricies, at first glance. Do you have a piece of information you want to assign to every index in a 3D matrix that isn't shown here?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by