Combining cells into a single cell

Hi there
I have a variable called z in a 9x1 cell. See the picture:
1.png
Is ther anyway to combine the cells to one cell like 360<181x1080?
Because when I run my data, z{:} in my code, I got the error "Expected one output from a curly brace or dot indexing expression, but there were 9 results."
So I think I should combine my 9 cells to one so I have one result?

5 comentarios

Luna
Luna el 28 de Dic. de 2018
What do you mean by < operator in this term: 360<181x1080?
And could you please share your code how do you use z{:} ?
Dou you want to merge all of these double arrays inside your z?
Stephen23
Stephen23 el 28 de Dic. de 2018
Editada: Stephen23 el 28 de Dic. de 2018
"Is ther anyway to combine the cells to one cell like 360<181x1080?"
Your 9x1 cell array contains double arrays (not cell arrays), so the combined array will also be a double array (not a cell array as you wrote).
It's here I use the z{:}
for i = 1:Nfiles
lon{i} = ncread(ncfiles(i).name, 'longitude');
lat{i} = ncread(ncfiles(i).name, 'latitude');
time{i} = ncread(ncfiles(i).name, 'time');
z{i} = ncread(ncfiles(i).name, 'z');
end
nx = length(lon{i});
ny = length(lat{i});
nt = length(vertcat(time{:}));
zmean = zeros([nx ny]);
blocks = zeros(nx);
for n = 1:nt
zx(:,1:ny) = z{:}(:,ny:-1:1);
zmean = zmean + zx;
end
Stephen23
Stephen23 el 29 de Dic. de 2018
Editada: Stephen23 el 29 de Dic. de 2018
If z is non-scalar (i.e. has zero or multiple cells) then this syntax will throw an error:
z{:}(:,ny:-1:1);
Do you have a question about the code that you showed us? I notice that the code you show does not use either of the answers that you have been given.
Jonas Damsbo
Jonas Damsbo el 29 de Dic. de 2018
Editada: Jonas Damsbo el 29 de Dic. de 2018
It's here I want a single cell for z. But I think Star Strider have make an answer I can use.

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 28 de Dic. de 2018
See if the cat (link) or cell2mat (link) or both will help solve your problem.
Example —
M{1} = rand(3,4,2);
M{2} = rand(3,4,2);
M{3} = rand(3,4,2);
Mcat = cat(3, M(1),M(2),M(3));
Mdbl = cell2mat(Mcat);
producing:
SizeMdbl = size(Mdbl)
SizeMdbl =
3 4 6
This seems to be the sort of result you want.

Categorías

Preguntada:

el 28 de Dic. de 2018

Editada:

el 29 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by