作业帮 > 综合 > 作业

Matlab程序中temp(ic)= [data id]= out(ir) = Data(ir,id);这三句看不懂 程

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 05:07:02
Matlab程序中temp(ic)= [data id]= out(ir) = Data(ir,id);这三句看不懂 程序为求Data每行出现最多的数
Data = [1 2 3 2 2;
4 3 1 5 4;
3 5 1 2 1;
3 3 1 1 3];
for ir = 1:size(Data,1)%行数
for ic = 1:size(Data,2)%列数
temp(ic) = size(find(Data(ir,:) == Data(ir,ic)),2);
end
[data id] = max(temp,[],2);
out(ir) = Data(ir,id);
end
out'
1、第一句:
temp(ic) = size(find(Data(ir,:) == Data(ir,ic)),2);
以ir=1,ic=2为例说明
>> Data(1,:)%第一行所有的数
ans =
1 2 3 2 2
>> Data(1,2)%第一行第二列的数
ans =
2
>> find(Data(1,:) == Data(1,2))%找出 “Data(1,:)中大小为Data(1,2)的数” 所在的列的序号
ans =
2 4 5
>> size(find(Data(1,:) == Data(1,2)),2)%计算 “Data(1,:)中大小为Data(1,2)的数” 的数目
ans =
3
2、第二句:
C = max(A,[],dim) returns
the largest elements along the dimension of A specified
by scalar dim.For example,max(A,[],1) produces
the maximum values along the first dimension (the rows) of A.
[C,I] = max(...) finds
the indices of the maximum values of A,and returns
them in output vector I.If there are several identical
maximum values,the index of the first one found is returned.
[data id] = max(temp,[],2);%求出temp每行最大的数data ,并返回该数的序号id
3、第三句
out(ir) = Data(ir,id); %ir为行数,id为出现最多次数的数所在的列
再问: 好的,理解的一半,亲再给我解释下[data id] = max(temp,[],2);这一句和out(ir) = Data(ir,id); 这一句好吗 谢谢了
再答: 已解答 2、第二句: C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension (the rows) of A. [C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned. [data id] = max(temp,[],2);%求出temp每行最大的数data ,并返回该数的序号id 3、第三句 out(ir) = Data(ir,id); %ir为行数,id为出现最多次数的数所在的列