How to convert the contents of a cell array into an array?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have a cell array that looks a bit like this:
N='AA' 'AA_BB' 'AA_BB_CC' 'AA_BB_DD' 'AA_BB_EE'
it is easy enough to convert a specific entry of my cell into an array:
a=cell2mat(N(2)) a=AA_BB
Now I want to use the cellfun code in order to generate an array for all the entries in my cell. The end result I am envisioning looks a bit like:
a=AA AA_BB AA_BB_CC AA_BB_DD AA_BB_EE
I am trying the following code:
a=cellfun(cell2mat,N)
but I am getting an error message. Where am I going wrong? Thanks
2 comentarios
Jan
el 10 de Sept. de 2013
Editada: Jan
el 10 de Sept. de 2013
If you have a cell array, post the code for a cell array also:
N = {'AA', 'AA_BB', 'AA_BB_CC', 'AA_BB_DD', 'AA_BB_EE'};
When you get an error message, post a complete copy in the forum. It is much easier to solve a problem than to guess, what the problem is.
Respuestas (1)
Jan
el 10 de Sept. de 2013
Editada: Jan
el 10 de Sept. de 2013
This is not a job for cellfun. And if it is one, a function handle would be required: cellfun(@cell2mat, ...) .
N = {'AA', 'AA_BB', 'AA_BB_CC', 'AA_BB_DD', 'AA_BB_EE'};
a = sprintf('%s ', N{:}); % Has a trailing space
% Or:
b = cat(2, N{:}); % No intermediate spaces
% Or:
c = CStr2String(N, ' ', 0);
5 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!