Borrar filtros
Borrar filtros

extract portion of each cell array elements using cellfun

3 visualizaciones (últimos 30 días)
I have a 5x9 cell array A. Each cell in A contains a 3x1 cell. In each cells, I have mesh data for a surface. For example A{1,1} have three 119x755 matrix in each cell. But the mesh matrix size in A{1,2} are not in the same size of A{1,1}. I want to make the mesh size all the same in each cell array for example 100x700. How can I do it using cellfun?
A =
3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell
3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell
3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell
3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell
3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell 3x1 cell
A{1,1} =
119x755 double
119x755 double
119x755 double
A{1,2} =
122x764 double
122x764 double
122x764 double
  1 comentario
Walter Roberson
Walter Roberson el 20 de Jul. de 2022
Do you want to pick the first 100 x 700 entries, throwing away the information in the remaining rows and columns?
Or do you want to interpolate the data down, such as doing an imresize() operation on it?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Jul. de 2022
newA = cellfun(@(C) cellfun(@(M) imresize(M, 100, 700), C, 'uniform', 0), A, 'uniform', 0);
  3 comentarios
Walter Roberson
Walter Roberson el 21 de Jul. de 2022
A = {{zeros(128, 800);; zeros(128,800)}, {ones(150, 900); ones(150, 900)}};
newA = cellfun(@(C) cellfun(@(M) imresize(M, [100, 700]), C, 'uniform', 0), A, 'uniform', 0);
newA{1}
ans = 2×1 cell array
{100×700 double} {100×700 double}
Katherine Zheng
Katherine Zheng el 21 de Jul. de 2022
Hi @Walter Roberson, Thanks very much. That works like a charm. Can I ask an additional qustion? Is there any way to ultilise cellfun if I want to modify how many rows to be extracted in each cell column? For example, for first column A{:,1}, I want the matrix size to be 100x700. For second column A{:,2}, I want the matrix size to be 200x700. I have an array to store the size I want in B. Is this possible?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by