extract portion of each cell array elements using cellfun

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-7-20
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?

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by