Write A Matlab Function of a matrix

Write a matlab function which accepts n (row) by m (col) matrix. The function will exclude the repeated elements and sort the rest of the elements in descending order. (You can use any reasonable way to solve this problem).
Can u please help me about this question

4 件のコメント

Rik
Rik 2018 年 1 月 14 日
What have you tried? You can find help here on this forum, but it is not meant as a free homework making service. You can find guidelines for posting homework on this forum here.
Jan
Jan 2018 年 1 月 14 日
The question is not clear: "exclude the repeated elements" is ambiguous. For the input [1, 2, 1, 3] this can mean [1, 2, 3] (remove the repetitions only) or [2, 3] (remove all elements which occur repeatedly).
Does "You can use any reasonable way to solve this problem" include to submit a solution, which was written by another person?
Rik
Rik 2018 年 1 月 14 日
Spam by flag must be the most stupid kind of posting spam. Am I correct in assuming people with the reputation level to remove this flag will see it?
John D'Errico
John D'Errico 2018 年 1 月 14 日
Removed. Both the spam flag, and the spam comment.

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

回答 (2 件)

ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 14 日
編集済み: ANKUR KUMAR 2018 年 1 月 14 日

2 投票

A=randi(25,25,100);
ss=func(A,10,20)
function S = func(A,m,n)
B=A(1:m,1:n);
C=B(:);
id=unique(C)
S=sort(id,'descend')
end

2 件のコメント

Jan
Jan 2018 年 1 月 14 日
編集済み: Jan 2018 年 1 月 14 日
Please do not post complete solution of homework questions. The teacher of the OP might consider this as trial to cheat.
I think, that "clc, clear" is not useful at all. As far as I understand the question, the input should be a [m x n] matrix directly.
ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 14 日
Sure Sir. I will not repeat the same.

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

Jan
Jan 2018 年 1 月 14 日

1 投票

If you are looking for a unique list of elements, start with a search in the documentation:
docsearch unique
You will find a command called unique(). See:
doc unique
Now its input should be a vector, not a matrix. Read the "Getting Started" chapter to learn, what A(:) does. For sorting:
docsearch sort
And again sort() is existing as command already.
doc sort

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2018 年 1 月 14 日

コメント済み:

2018 年 1 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by