How do I convert a cell array to matrix whose dimensions are not equal?

mydata =
[195x1 double] [124x1 double] [1826x1 double] [2x1826 double] [195x124x1826 single]

댓글 수: 5

Convert into what?
For what purpose?
Manoj - are you trying to convert the above to a matrix using cell2mat? If so, what are the dimensions of the matrix that you are trying to obtain? Please show the code that you have written that generates the error.
Geoff Hayes
Pls find the attachment of the .jpg images having the cell array of B consists the data of different dimensions. I need to convert the cell array in to matrix form with different file names, so that I can choose the data for plotting.
Thanks
Manoj Kumar
I neither understand the meanig of the images, not the description "matrix form with different file names".
Manoj - how should all of this data, from your cell array, be packaged into the matrix? What should the dimensions be for the matrix?

댓글을 달려면 로그인하십시오.

 채택된 답변

%using variable names from your posting, structure as in capture.JPG
md1 = mydata{1};
md2 = mydata{2};
md3 = mydata{3};
md4 = mydata{4};
md5 = mydata{5};
[X, Y, Z] = ndgrid(md1, md2, md3);
pointsize = 20;
scatter3(X(:), Y(:), Z(:), pointsize, md5(:));
%using variable names from data file.JPG
%the data is a mix of int16 and int32 and we need to make it all the same datatype to
%make it into a numeric matrix without risk that the wrong datatype would be used
temp = cellfun(@(M) int32(M.'), permute(B,[1 3 2]), 'Uniform', 0);
B30 = cell2mat( arrayfun(@(R) horzcat(temp{R,:}), 'Uniform', 0) );
The result of this, B30, would be a 30 x 10666 numeric array, in which each row is formed by concatenating together the 2446 x 1, 2532 x 1, 2651 x 1, 3037 x 1 as one piece and making that a row.

댓글 수: 3

Thank you for your reply
but I am getting two errors after running the below code.
1)
md = mydata{1};
md1 = mydata{2};
md2 = mydata{3};
[X Y Z]=ndgrid(md,md1,md2);
temp = cellfun(@(M) int32(M.'), permute(B,[1 3 2]), 'Uniform', 0);
B30 = cell2mat( arrayfun(@(R) horzcat(temp{R,:}), 'Uniform', 0) );
Error using repmat
Requested 5949x5949x5949 (1568.6GB) array exceeds maximum array size preference. Creation of arrays greater than this
limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more
information.
Error in ndgrid (line 73)
varargout{i} = repmat(x,s);
2)
md = mydata{1};
md1 = mydata{2};
[X Y]=ndgrid(md,md1);
temp = cellfun(@(M) int32(M.'), permute(B,[1 3 2]), 'Uniform', 0);
B30 = cell2mat( arrayfun(@(R) horzcat(temp{R,:}), 'Uniform', 0) );
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 7 in dimension 2. Input #3 has size 1
You have changed the size of your data in mydata. Please show the current summary of mydata and also of B.
The line
B30 = cell2mat( arrayfun(@(R) horzcat(temp{R,:}), 'Uniform', 0) );
should be
B30 = cell2mat( arrayfun(@(R) horzcat(temp{R,:}), 1:size(temp,1), 'Uniform', 0) );

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2016년 2월 10일

댓글:

2016년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by