extract portion of each cell array elements using cellfun

8 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 20 Jul 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?

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!