How to treat select elements from within multiple cells as a single vector

5 ビュー (過去 30 日間)
Gabriel Stanley
Gabriel Stanley 2022 年 9 月 26 日
コメント済み: Gabriel Stanley 2022 年 9 月 26 日
What is the proper syntax for this indexing?:
ContainerArray = cell(13,9);
[ContainerAray{:,:}] = deal(rand(1,6))
DesiredVector = sum(ContainerArray{2:end,1}(1,1))
That is, how to I extract the nth elements of the arrays contained in the first cell column, cell rows 2:end (or really any cell index), and treat those extracted nth elements as a single array/vector?
  2 件のコメント
David Hill
David Hill 2022 年 9 月 26 日
Why use a cell array if all entries are doubles?
Gabriel Stanley
Gabriel Stanley 2022 年 9 月 26 日
Actual data isn't, was trying to quicky create some dummy data to help illustrate basic problem. Also, even if all array are of the same type, individual arrays could be different sizes as long as a known index (e.g. (1,1)) was guaranteed to exist.

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

採用された回答

Jan
Jan 2022 年 9 月 26 日
編集済み: Jan 2022 年 9 月 26 日
C = cell(5, 4);
C(:) = {2:5}; % Faster than with DEAL
V = cellfun(@(x) x(1,1), C(2:end,1), 'UniformOutput', 1)
V = 4×1
2 2 2 2
V = sum(V)
V = 8
  3 件のコメント
Gabriel Stanley
Gabriel Stanley 2022 年 9 月 26 日
yeah, that. Sorry, running on very little sleep atm.

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

その他の回答 (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