PADCAT on cells with nested cells
Mostrar comentarios más antiguos
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)?
padcat can be downloaded from the File Exchange: https://uk.mathworks.com/matlabcentral/fileexchange/22909-padcat-varargin-
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 comentarios
Max Murphy
el 28 de Dic. de 2019
Editada: Max Murphy
el 28 de Dic. de 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?
jenifer Ask
el 29 de Dic. de 2019
Editada: jenifer Ask
el 29 de Dic. de 2019
Stephen23
el 29 de Dic. de 2019
"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.
jenifer Ask
el 29 de Dic. de 2019
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
el 29 de Dic. de 2019
Editada: jenifer Ask
el 30 de Dic. de 2019
Respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!