How do i check the frequency of an element in a multi level cell array?
1 回表示 (過去 30 日間)
古いコメントを表示
Prajwal Venkatesh
2020 年 1 月 20 日
コメント済み: Turlough Hughes
2020 年 1 月 24 日
The multi level cell array has 61 cells and each of these 61 elements have around 25*30 cells.
7 件のコメント
Turlough Hughes
2020 年 1 月 23 日
Is there a reason you need a new array with similar structure to results2? It'd probably be much easier to make a unique list of the strings and list the corresponding frequencies alongside them.
Secondly, it's worth confirming what Dinesh asked with the following code:
test = cellfun(@(x) cellfun(@class,x,'UniformOutput',false),results2,'UniformOutput',false);
unique(vertcat(test{:}))
Or better yet, attach results2, with the paperclip button.
採用された回答
Turlough Hughes
2020 年 1 月 23 日
編集済み: Turlough Hughes
2020 年 1 月 24 日
The following loads and concatenates all elements of your cell array, including the 1 x 2 string in result2{1,1}(7), into a single column string array called elements:
load asd
elements = vertcat(result2{:});
elements = [elements{:}].';
The next step is to get a unique list of names and the index iNames which can be used to get frequency as follows:
[NameList,~,iNames] = unique(elements,'stable');
Frequency = histcounts(iNames,numel(NameList)).';
T = table(NameList, Frequency)
The second input to the unique function is used to maintain the order of the input array, you might also like to have a look at the documentation on unique regarding the third output.
Edit: Modified unique to maintain the order and included some description of the code.
2 件のコメント
Turlough Hughes
2020 年 1 月 24 日
I modified my answer slightly; just including 'stable' on the second input to the unique function. The table, T, then has the results ordered according to how they first appear in result2, moving through your original cell array as follows: result2{1,1}, result2{1,2}, result2{1,3}, etc. I assume that's what you mean.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!