Effacer les filtres
Effacer les filtres

extract portion of each cell array elements using cellfun

3 vues (au cours des 30 derniers jours)
Katherine Zheng
Katherine Zheng le 20 Juil 2022
Commenté : Katherine Zheng le 21 Juil 2022
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 commentaire
Walter Roberson
Walter Roberson le 20 Juil 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?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Juil 2022
newA = cellfun(@(C) cellfun(@(M) imresize(M, 100, 700), C, 'uniform', 0), A, 'uniform', 0);
  3 commentaires
Walter Roberson
Walter Roberson le 21 Juil 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 le 21 Juil 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by