필터 지우기
필터 지우기

How to find the frequency of individual elements in a matrix?

조회 수: 41 (최근 30일)
Prince
Prince 2024년 4월 4일 16:20
편집: Dyuman Joshi 2024년 4월 4일 16:56
How do I find the frequencies of all the elements in the matrix attached and also draw a histogram knowing the frequencies of the elements?

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 4월 4일 16:42
편집: Dyuman Joshi 2024년 4월 4일 16:56
MATLAB has a in-built function for it - histogram, which does both the operations in single command -
s = load('micro2d (2).mat')
s = struct with fields:
Expression1: [150x150 double]
vec = s.Expression1(:).';
val = unique(vec);
h = histogram(vec, [val Inf])
h =
Histogram with properties: Data: [2180 3888 3888 3888 3888 3888 3888 4514 4718 4718 4718 4718 4718 4718 4718 4718 4718 4718 2133 2133 2133 802 3805 3805 3805 3805 3805 3805 ... ] (1x22500 double) Values: [76 18 25 114 36 62 50 76 114 150 52 66 76 34 55 35 33 57 53 101 60 38 42 32 74 31 13 50 78 42 2 105 39 56 109 3 10 63 56 127 68 113 57 45 23 ... ] (1x420 double) NumBins: 420 BinEdges: [20 24 45 50 84 102 105 114 129 133 135 136 145 157 178 193 194 201 210 212 233 270 280 286 335 356 370 371 382 396 407 410 412 413 422 437 ... ] (1x421 double) BinWidth: 'nonuniform' BinLimits: [20 Inf] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Use GET to show all properties
%numbers
val
val = 1x420
20 24 45 50 84 102 105 114 129 133 135 136 145 157 178 193 194 201 210 212 233 270 280 286 335 356 370 371 382 396
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%corresponding frequencies
freq = h.Values
freq = 1x420
76 18 25 114 36 62 50 76 114 150 52 66 76 34 55 35 33 57 53 101 60 38 42 32 74 31 13 50 78 42
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by