Error using histc. First Input must be a real non-sparse numeric array.

5 ビュー (過去 30 日間)
Rajat  Saxena
Rajat Saxena 2016 年 12 月 27 日
編集済み: dpb 2016 年 12 月 28 日
data = load('Day10.mat');
data = data.timestamps;
data{1} = data{1,1}';
data{2} = data{1,2}';
data{3} = data{1,3}';
data{4} = data{1,4}';
data{5} = data{1,5}';
data{6} = data{1,6}';
data{7} = data{1,7}';
data{8} = data{1,8}';
edges = [0 33.3115 33.3125 33.3135 33.3145 33.3155 33.3165 33.3175 33.3185 Inf];
n = histc(data, edges);
bar(n, 'histc');
set(gca,'XTick',1:length(edges),'XTickLabel', {edges(1:10)});
legend('cam1','cam2','cam3','cam4','cam5','cam6','cam7','cam8');
legend('show');
xlabel('Time(ms.)');
ylabel('Count');
The above shown script is what I am using to generate histogram which should look something like this:
But I am not able to do it. Can anyone suggest me how to go about do this? The data is stored in this format:
The timestamps variable is 1*8 cell with each cell containing 1*213549 double values.

採用された回答

Walter Roberson
Walter Roberson 2016 年 12 月 27 日
編集済み: Walter Roberson 2016 年 12 月 27 日
temp = cellfun@(X) reshape(histc(X, edges), [], 1), data, 'Uniform', 0);
n = horzcat(temp{:});

その他の回答 (1 件)

dpb
dpb 2016 年 12 月 27 日
Use cell2mat to "smoosh" the cell arrays into one array before histc
If have later release, there's a newer histogram function that just might be cell array literate, not sure, but worth checking, perhaps...
  4 件のコメント
Walter Roberson
Walter Roberson 2016 年 12 月 27 日
Ah, you are right, cell2mat could turn that into an array whose columns histc() would operate over. That is a better solution than what I did.
dpb
dpb 2016 年 12 月 28 日
編集済み: dpb 2016 年 12 月 28 日
Whew! :) Thought it was ok when posted it... vbg
Does the newer histogram function work more better here than " histc classic"?

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by