列出数组中的所有值而不重复 [英] List all values in an array without repeats

查看:71
本文介绍了列出数组中的所有值而不重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个100 x 100的矩阵,由250s,125s,15s和9s的某种组合组成.我想返回此矩阵中所有唯一值的排序向量.

Suppose I have a 100 x 100 matrix composed of some combination of 250s, 125s, 15s and 9s. I would like to return a sorted vector of all of the unique values in this matrix.

有关某事的事情

sort(somefunction(matrix))=vector 

我想得到的结果是:

vector=9,15,125,250

有没有一种快速简便的方法来做到这一点?

Is there a quick and easy way to do this?

推荐答案

b = unique(a)

unique

A = randi(9,10,10);
unique(A)
ans =
     1
     2
     3
     4
     5
     6
     7
     8
     9

这篇关于列出数组中的所有值而不重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆