How to create a vector by indexing elements within each cell of a 1xN cell array

1 回表示 (過去 30 日間)
I have a 1xN cell array (raw_array) and I am trying to create a vector of N values using the same indexing (a,b) within each cell.
I can use this expression to extract a scalar value from a single cell:
raw_array{1,n(x,y)}(a,b)
Here n(x,y) is just a means of indexing the correct cell within the cell array.
Let's say y varies from 1-10, i earlier tried the following:
raw_array{1,n(x,1:10)}(a,b) but clearly this doesn't work (error msg: Expected one output from a curly brace or dot indexing expression, but there were 10 results).
I really want to avoid writing each vector element separately, e.g. [raw_array{1,n(x,1)}(a,b) raw_array{1,n(x,2)}(a,b)...]
Can anybody please give me a hint or suggestion?
Thanks

採用された回答

Stephen23
Stephen23 2021 年 5 月 14 日
編集済み: Stephen23 2021 年 5 月 14 日
Where C is your cell array:
a = ..;
b = ..;
F = @(m)m(a,b);
V = cellfun(F,C)
  9 件のコメント
Stephen23
Stephen23 2021 年 5 月 17 日
Sorry, the code I posted earlier was not correct. Please show the output of this:
for k = 1:numel(raw_array)
size(raw_array{k})
end
Daniel Rowe
Daniel Rowe 2021 年 5 月 17 日
No problem, I have reworked the code now so that it makes more sense. Thanks!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by