在matlab中分配标签和创建排序列表?

时间:2014-02-06 17:10:27

标签: matlab sorting matrix

我缺乏matlab的经验,&编写程序代码时出现问题,如下所示:

N = input('Enter N:');     % The number of rows (say 6)
M = input('Enter M:');     % The number of columns (say 4)
Mat1 = round(rand(N,M));   % Creating a random binary matrix
B = sum(Mat1);           % Calculating the sum of the elements of the columns
Mat2 = sort(B,'descend')   % Sorting the elements in a descending order

我要做的事情如下:

1- Mat1必须将其行和列分配为:

   C1 C2 C3 C4
N1  0  1  1  1
N2  0  0  1  1
N3  0  1  1  0
N4  0  1  0  1
N5  1  1  0  1
N6  1  0  0  1

2- Mat2应显示列的指定标签,而不是总和值:

Mat2 = [C4 C2 C3 C1]    % The labels of the columns

除了

Mat2 = [5 4 3 2]    % The sorting of the columns in a descending order

3 Mat1必须分为2XN子集;例如:

   C1 C2 C3 C4
N1  0  1  1  1
N2  0  0  1  1

4-在每个子集中,创建一个列表,其中包含仅包含 1 的列,例如:

N1N2 = [C3 C4]   % Ascending sorting is done according to the values of Mat2

希望解释清楚。感谢您提供的任何帮助。

0 个答案:

没有答案