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

14 次查看(过去 30 天)
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!

采纳的回答

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

更多回答(1 个)

the cyclist
the cyclist 2022-3-8
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.)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by