How to append a large number of cell arrays vertically?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Behrooz Daneshian
el 19 de Mzo. de 2023
Editada: the cyclist
el 19 de Mzo. de 2023
Hi all,
I have a large number of cell arrays that I need to append all of them vetically into a unique cell array. I do not want to load each of cell array individually and then append all of them. Can anyone tell me how I can do it in the most efficient way?
Thanks in advance for your asnwers.
2 comentarios
Respuesta aceptada
Matt J
el 19 de Mzo. de 2023
Editada: Matt J
el 19 de Mzo. de 2023
s=dir('stations_*.mat');
CellList=cellfun(@(z) load(z).stations1,{s.name},'uni',0);
result=vertcat(CellList{:})
3 comentarios
the cyclist
el 19 de Mzo. de 2023
Editada: the cyclist
el 19 de Mzo. de 2023
Just to expand @Matt J's answer a bit. He used an anonymous function to accomplish the task. z is a dummy variable that will be substituted out by the values in the cell array (from the second argument to cellfun).
A simple example of an anonymous function is
func_sqr = @(x) x.^2
func_sqr([2 3 5])
You can see that x (like z in Matt's example) is just a placeholder variable in the function definition.
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!