How to count repeated numbers and perform statistic on it?

2 ビュー (過去 30 日間)
Xiu Wen Kang
Xiu Wen Kang 2022 年 11 月 30 日
コメント済み: Xiu Wen Kang 2022 年 12 月 2 日
Hi all,
I have a two column arrays where one represent time, the other are either 1, -1 or 0 which representing three different structures of my molecules.
for example of A = [
94.668 -1
94.67 1
94.672 -1
94.674 -1
94.676 0
94.678 1
94.68 -1
94.682 -1
94.684 -1
94.686 1
94.688 -1
94.69 1
94.692 -1
94.694 1
94.696 1
94.698 -1
94.7 -1
94.702 1
94.704 -1
94.706 -1
94.708 -1
94.71 1 ]
I want to count for example, structure(1) continuous of 2 array elements has how many of them, continuous of 3 array elements has how many of them, etc.
also the same statistic calculation for structure (-1) and structure (0).
so by looking at the above example, (-1) repeating 1 has 3, (-1) repeating 2 has 2 (-1) repeating 3 has 2, (0) repeating 1 has 1, (1) repeating 1 has 5, .....
the total length of my arays is 90000 X 2, which is large quantity of numbers to calculate manually, so may I as how can I write a matlab script to account for this problem?
Thank you !

採用された回答

Image Analyst
Image Analyst 2022 年 11 月 30 日
Try this:
A = [
94.668 -1
94.67 1
94.672 -1
94.674 -1
94.676 0
94.678 1
94.68 -1
94.682 -1
94.684 -1
94.686 1
94.688 -1
94.69 1
94.692 -1
94.694 1
94.696 1
94.698 -1
94.7 -1
94.702 1
94.704 -1
94.706 -1
94.708 -1
94.71 1 ];
% Find distribution of -1 runs.
mask = A(:, 2) == -1;
props = regionprops(mask, 'Area');
areaMinus1 = [props.Area];
subplot(3, 1, 1);
histogram(areaMinus1)
grid on;
title('Distribution of -1 runs')
xlabel('Run Length')
ylabel('Count')
drawnow;
% Find distribution of 0 runs.
mask = A(:, 2) == 0;
props = regionprops(mask, 'Area');
areas0 = [props.Area];
subplot(3, 1, 2);
histogram(areas0)
grid on;
title('Distribution of 0 runs')
xlabel('Run Length')
ylabel('Count')
drawnow;
% Find distribution of 1 runs.
mask = A(:, 2) == 1;
props = regionprops(mask, 'Area');
areas1 = [props.Area];
subplot(3, 1, 3);
histogram(areas1)
grid on;
title('Distribution of 1 runs')
xlabel('Run Length')
ylabel('Count')
drawnow;
  3 件のコメント
Xiu Wen Kang
Xiu Wen Kang 2022 年 12 月 2 日
Thanks for your help!
I will give it a go :)

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by