フィルターのクリア

How to create a loop generating bins for the group of data in cell array

2 ビュー (過去 30 日間)
Hi everyone,
I am a newby to MathLab and I need some help from the community.
I am trying to figure out how to loop a simple histcounts function.
I have a data set which I separtated into cell arrays with accumarrays
So now I have a cell array GC{121:1} which contain 121 separate matrixes (double values). Each of those matrixes has 2 columns and diferent numer of rows (2 x n matrix ).The first colunm is the number of slice indicating were data were extracted from.
I would like to split each matrix into 10 equal bins by the second column. So far I got to this:
But the loop I wrote dose not work
GC = accumarray(data(:,1),(1:size(data,1)),[],@(x){data(x,:)});
% Distribute x_point column into 6 equally spaced bins..
for i=1:121
[N,edges] = histcounts(GC{i,1},10);
end
  3 件のコメント
Iuliia Myrgorodska
Iuliia Myrgorodska 2020 年 4 月 25 日
Yes,
that's exactly the problem I have. Do you know how can I fiix this?
Iuliia Myrgorodska
Iuliia Myrgorodska 2020 年 4 月 25 日
How can I save the result in another set of cel arrys? so that I get the results from all iteration as one set?

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

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 25 日
Hi Luliia,
The problem here is that the variables N and edges are overwritten with the latest value each time in the for loop.
You can try the following:
GC = accumarray(data(:,1),(1:size(data,1)),[],@(x){data(x,:)});
% Distribute x_point column into 6 equally spaced bins..
N = cell(1,121);
edges = cell(1,121);
for i=1:121
[N{i},edges{i}] = histcounts(GC{i,1},10);
end
% To access the first value in N, it can be done through N{1}
Hope this helps.
Regards,
Sriram
  1 件のコメント
Iuliia Myrgorodska
Iuliia Myrgorodska 2020 年 4 月 25 日
Awsome, thanks a lot. I couldn't figure the syntaxys))

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by