Unpacking and tabulating contents of a cell array

25 ビュー (過去 30 日間)
Ryan Graham
Ryan Graham 2021 年 3 月 9 日
コメント済み: Ryan Graham 2021 年 3 月 9 日
Hi, I have the following cell array:
My goal is to unpack the contents of each cell and tabulate the amount of times each number occurs. My first attempt below unpacks each cell in the command window and only the final 25th cell in the workspace under 'ans':
vsel{:}
My second attempt only returns the 1st of 25 cells in a new array in the workspace:
h = size(vsel,1);
vsel = vsel{1:h,1};
My third attempt was to use a comma separated list and employ concatenation but that only appears to work on arrays where each cell is of the same dimensions:
matrix = vertcat(vsel{:});
Once I can extract this information, I plan on tabulating the amount of times each number appears in each cell. Any help would be greatly appreciated!
-Ryan
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 9 日
In the posted data, the entries are all sorted and no entry occurs more than once per cell. Are those characteristics that can be counted on?
Ryan Graham
Ryan Graham 2021 年 3 月 9 日
Hi Stephen and Walter,
Thanks for your help. This is an adaptive - reweighted iterative sampling approach that will always return a 25x1 cell array. However, the contents of each cell in the array can range from 1:2 to 1:50. Using Walter's initial approach, I was able to create a histogram of how many times each number appeared in total for the 25x1 array using the following:
edges = unique(allnumbers)
counts = histc(allnumbers(:),edges)
bar(counts)

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 9 日
all_numbers = horzcat(vsel{:});
This is the same as
all_numbers = [vsel{:}];
  1 件のコメント
Ryan Graham
Ryan Graham 2021 年 3 月 9 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by