フィルターのクリア

Extracting single numbers from each cell in a cell array

17 ビュー (過去 30 日間)
Guglielmo Sonnino Sorisio
Guglielmo Sonnino Sorisio 2022 年 3 月 21 日
編集済み: Voss 2022 年 3 月 21 日
I have a 451x1 cell array, each cell is a 57x41 double. From each cell (which represents a timepoint) I need to extract the value of one location, the same one for all cells. e.g. From all 451 cells I need to extract (32, 25) from the 57x41 double. I then need to combine these into a 451x1 double. How can I do this? I'm having trouble getting the correct notation.
Thank you

採用された回答

Voss
Voss 2022 年 3 月 21 日
% first, create a cell array like yours:
C = cell(451,1);
for ii = 1:numel(C)
C{ii} = randn(57,41);
end
% look at the first couple of cells' (32,25) element:
C{1}(32,25)
ans = -0.4494
C{2}(32,25)
ans = -0.5907
% now get the specified element from each cell into a double array:
A = cellfun(@(x)x(32,25),C)
A = 451×1
-0.4494 -0.5907 -0.8715 -1.0468 0.4059 -0.2548 -0.2243 -0.9131 0.9573 -0.2997
  2 件のコメント
Guglielmo Sonnino Sorisio
Guglielmo Sonnino Sorisio 2022 年 3 月 21 日
Thank you,
I'm not sure where I need to substitute the name of the cell array in the code you wrote, if I run it like you wrote it I get the correct output but if I try to substitute the name of the cell array (which is u_filtered) it gives me error messages.
Voss
Voss 2022 年 3 月 21 日
編集済み: Voss 2022 年 3 月 21 日
Anywhere my code uses C, your code should use u_filtered, but it's really just one line to do the actual indexing (the rest is to create my cell array, which you already have):
% get the specified element from each cell into a double array:
A = cellfun(@(x)x(32,25),u_filtered)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by