Is it possible to create a variable like list of numbers from other matrix?

14 views (last 30 days)
For example, I have random matrix 10*10, and I want to create array of numbers that my matrix has, and if some of numbers repeat at matrix several times, show this numbers in my "list" ones.
Thank you!

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Mar 2022
Use the unique function.
a = [1 2 3 3 3];
b = unique(a)
b = 1×3
1 2 3

More Answers (1)

the cyclist
the cyclist on 8 Mar 2022
Is this what you mean? I'll illustrate with a smaller matrix.
M = [ 2 2;
3 5;
7 7;
9 11;
13 13];
[numberOfOccurrences, uniqueValues] = histcounts(M(:)',[unique(M(:))' Inf])
numberOfOccurrences = 1×7
2 1 1 2 1 1 2
uniqueValues = 1×8
2 3 5 7 9 11 13 Inf
(You can obviously get rid of the Inf value. It's necessary because of the way that histcounts does the binning.)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!