PADCAT on cells with nested cells

try to use Padcat function on my cells, but I can't, because my cells include nested cells, Attached my fils (6*47). (6 is number my images).
how to change this code to access the correct result (matrix with size 6*n)?
load ('rotate.mat')
a_2=rotatedImage;
for i=1:6
[m{i}, tf{i}] = padcat(a_2(i,:))'; % concatenate, pad rows with NaNs
m{i}(~tf{i}) = 0 % replace N
vec_rotate{i}= cell2mat(a_2(i,:))' ;
vec_rotate{i}=vec_rotate(i,:)'
end

7 Comments

Max Murphy
Max Murphy on 28 Dec 2019
Edited: Max Murphy on 28 Dec 2019
I'm not sure I entirely understand your data structure in rotate.mat. There are 6 rows in the cell array contained by that file (rotatedImage). Each cell element within your array contains a 5x5 logical array, which I assume is some operation applied to a subset of pixels within the image corresponding to that cell array row.
Are you trying to pad the individual cell elements so that instead of being 5x5 arrays they are now 6x6?
"try to use Padcat function on my cells, but I can't, because my cells include nested cells..."
Your uploaded data does not contain any nested cell arrays, the cell array contains either empty numeric arrays or 5x5 logical arrays:
>> load('rotate.mat')
>> fun = @(a)(isnumeric(a)&&isempty(a))||(islogical(a)&&all(size(a)==[5,5]));
>> all(cellfun(fun,rotatedImage(:)))
ans =
1
You call padcat with only one input argument, which (if it worked) would concatenate that one input with ... nothing. If you want to use padcat you should read its documentation: it clearly states that each vector needs to be provided as one input argument. Which would also tell you that you cannot use padcat: it is defined for vectors only, not 5x5 matrices like you have:
>> padcat(true(5,5),false(5,5))
Error using padcat (line 92)
Inputs should be all row vectors or all column vectors.
"how to change this code to access the correct result (matrix with size 6*n)? "
Your cell array contains logical/numeric arrays with sizes 0x0 or 5x5: how do you want to concatenate those arrays in such as way to get one single 6xN array?
Thank you for Reply
for example, to convert One image in which the attached file, I can convert to single vector. I want applying this to many images that different length size cells. ( that I cant)....
load ('One_image.mat')
rotatedImage=rotatedImage;
vec_rotatedImage= cell2mat(rotatedImage(:))' ; %OK 1*425
vec_rotatedImage=vec_rotatedImage(:)'
I have different files that matrices in cells and very necessary for me to find a solution to convert these files to single vector 6*n...
can you help me please...
"can you help me please..."
Once you actually explain what you are trying to do clearly, then probably someone can help you. The reason that your question has remained unanswered is because it is unclear what you are actually trying to do with your 6x47 cell array and its contents.
For example, in your previous comment you uploaded a 1x17 cell array (containing only 5x5 logical matrices), but nowhere did you explain how this 1x17 cell array relates to your original 6x47 cell array.
Your showed this code:
load ('One_image.mat')
rotatedImage=rotatedImage; % pointless
vec_rotatedImage= cell2mat(rotatedImage(:))'
However when I tried it with your uploaded data I do not get a vector (as your variable name indicates):
>> load('one_image.mat')
>> vec_rotatedImage = cell2mat(rotatedImage(:)).';
>> size(vec_rotatedImage)
ans =
5 85
Probably someone can help you, but only if you actually provide a clear explanation of what you are trying to achieve and provide data and/or code that actually matches your descriptions.
I have 6 images. In each, I have identified a number of different special points on which to extract the attributes. (Because of the different cell)
In the first image I have 15 matrices, 3 x 3. And so there are the number of special points in each matrix image.
First, I want to transform the individual matrices of each cell into vectors. Then paste them into their own rows.
I know a simple matrix can be transformed into a vector with (:). But I can't work with that many cells.
As far as I can tell, you are trying to do something like this:
C = cellfun(@(a)a(:).',Gmag,'uni',0); % all matrices -> row vectors
C(cellfun(@isempty,C)) = {zeros(1,9)}; % replace empty arrays with zeros
M = cell2mat(C); % convert to 6x423 numeric matrix
jenifer Ask
jenifer Ask on 29 Dec 2019
Edited: jenifer Ask on 30 Dec 2019
It's amazing ... thank you very much

Sign in to comment.

Answers (0)

Categories

Asked:

on 28 Dec 2019

Edited:

on 30 Dec 2019

Community Treasure Hunt

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

Start Hunting!