How can I convert a 3 dimensional matrix into a single cell

7 views (last 30 days)
How can I convert a 3d matrix into a cell array with 1*1 dimension which would then open the 3 dimensional matrix
  2 Comments
James Tursa
James Tursa on 19 Apr 2016
I don't understand what "would then open the 3 dimensional matrix" means. Can you give a short example? E.g., suppose you had a 4x3x2 array ... what would your cell array look like?
bhavya vendra
bhavya vendra on 19 Apr 2016
I have a 1024*1024 *80 image stack converted to a matrix. I need it to be in a 1*1 cell that would contain this matrix. This is what I have right now
if true
clear all
clc
folder = 'E:\Users\bvendra\Desktop\4.13umgs3-14c2before20,30, almost40\20\tif';
D = 'E:\Users\bvendra\Desktop\4.13umgs3-14c2before20,30, almost40\20\tif';
dCell = dir([D,'.tif']);
% NOTE: CHANGE FILETYPE AS APPROPRIATE FOR EACH SEQUENCE (.png, *.bmp, or *.jpg)
N = 80
numRows = ceil(sqrt(N));
IMAGES = cell(1,N);
FNAMEFMT = '%d.tif';
% Load images
for i=1:N
a = imread(sprintf(FNAMEFMT, i));
end
save vol01
end

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 20 Apr 2016

More Answers (1)

Kelly Kearney
Kelly Kearney on 19 Apr 2016
Is this what you want?
x = rand(4,3,2);
x = {x};
  2 Comments
bhavya vendra
bhavya vendra on 19 Apr 2016
Hello,
This lets me put the matrix in a cell but now I am losing the 3rd dimension of the matrix. I have my code attached below. My matrix is 1024*1024*80 and the cell only seems to display 1024*1024. Is there a way to fix it?
if true
if true
clear all
clc
folder = 'E:\Users\bvendra\Desktop\4.13umgs3-14c2before20,30, almost40\20\tif';
D = 'E:\Users\bvendra\Desktop\4.13umgs3-14c2before20,30, almost40\20\tif';
dCell = dir([D,'.tif']);
% NOTE: CHANGE FILETYPE AS APPROPRIATE FOR EACH SEQUENCE (.png, *.bmp, or *.jpg)
N = 80
numRows = ceil(sqrt(N));
IMAGES = cell(1,N);
FNAMEFMT = '%d.tif';
% Load images
for i=1:N
a = imread(sprintf(FNAMEFMT, i));
end
save vol01
end
end
Kelly Kearney
Kelly Kearney on 20 Apr 2016
I assume a is supposed to be a 3D matrix? Right now, you're overwriting the data on each iteration of the loop. Instead, save each image to a single slice of the matrix:
a = zeros(1024,1024,N);
for ii = 1:N
a(:,:,ii) = imread(sprintf(FNAMFMT, ii));
end

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!