フィルターのクリア

extract portion of each cell array elements using cellfun

1 回表示 (過去 30 日間)
Katherine Zheng
Katherine Zheng 2022 年 7 月 20 日
コメント済み: Katherine Zheng 2022 年 7 月 21 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by