フィルターのクリア

Finding the double array with most number of elements in a cell.

2 ビュー (過去 30 日間)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021 年 7 月 13 日
コメント済み: Image Analyst 2021 年 7 月 13 日
Hey all! I have a variable called "spikes" which is a 65X64 cell. Each cell consists of a double array woth varying number of elements in it as shown in the screenshot below. Now, for a particular row, I want to retrieve which double array has the most number of elements in it. What might be the best way to go about this? Thanks in advance!

採用された回答

Image Analyst
Image Analyst 2021 年 7 月 13 日
Did you try just a brute force approach? Untested code (because you forgot to actually attach your variable in a mat file).
[rows, columns] = size(spikes);
numElements = zeros(rows, columns);
for col = 1 : columns
for row = 1 : rows
thisCellsContents = spikes(row, col);
numElements(row, col) = numel(thisCellsContents);
end
end
mostElements = max(numElements(:));
% Find out what row and column it appears at (may be more than 1 cell).
[maxRowIndexes, maxColIndexes] = numElements == mostElements;
It's straightforward and intuitive. But I'm sure someone will come up with a shorter but more cryptic way of using cellfun() if you'd rather do it that way.
  2 件のコメント
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021 年 7 月 13 日
Thanks for your response! I've edited the query with the attached .mat file. The above code gives me this error when running it.
Error using ==
Too many output arguments.
Error in find_channel (line 11)
[maxRowIndexes, maxColIndexes] = numElements == mostElements;
Image Analyst
Image Analyst 2021 年 7 月 13 日
Sorry, should be
[maxRowIndexes, maxColIndexes] = find(numElements == mostElements);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by