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(Dat

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/13 03:51:05

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为出现最多次数的数所在的列

temp(ic) = size(find(Data(ir,:) == Data(ir,ic)),2);
find(Data(ir,:) == Data(ir,ic)) 返回第ir行 中和 第ir行ic列相同的元素的下标
有一个相同,find就返回一个下标,有n个相同,就返回n个下标
再用size(find(...),2)统计find到的个数
因此在内曾循环结束后

全部展开

temp(ic) = size(find(Data(ir,:) == Data(ir,ic)),2);
find(Data(ir,:) == Data(ir,ic)) 返回第ir行 中和 第ir行ic列相同的元素的下标
有一个相同,find就返回一个下标,有n个相同,就返回n个下标
再用size(find(...),2)统计find到的个数
因此在内曾循环结束后
temp是个长度和原来矩阵列数一样的向量
第一个数纪律ir行中,与ir行1列相同的元素的个数
第二个数纪律ir行中,与ir行2列相同的元素的个数,依次类推
内层循环结束后,再根据temp找出出现最多的数
[data id] = max(temp,[],2);
max寻找temp中最大的数,数值返回给data,下标位置返回给id
由于max无论有多少个相同的最大值,只返回一个最大值
所以返回data和id都只是一个数,而data还没有用,我们只需要id
out(ir) = Data(ir,id);
输出的第ir个数 赋值为Data的第ir行,id列的数
由于之前的工作已经确定,第ir行,重复最多的数的列下标是id
所有Data(ir,id)就是ir行,出现最多的数把它赋值给out(ir)
外循环也结束的时候,所有行都统计完成
out(1) 就是第1行出现最多的数
out(2) 就是第2行出现最多的数
依次类推

收起

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(Dat matlab语言中这句话 [temp MaxY]=max(Blue_y); 在单片机C中temp=temp & matlab中的程序是什么意思?E=[e(wb,:),wa,wb]; temp=find(E(:,1)-E(:,2))matlab中的程序是什么意思?其中wa、wb、wc是变量.e是矩阵E=[e(wb,:),wa,wb];temp=find(E(:,1)-E(:,2))前面矩阵E中含有矩阵e是什么意思?后面E从三 MATLAB中temp = I(t1(i):t2(i), t3(j):t4(j));什么意思 matlab语句中语句的区别temp(1:100) = traffic_models.data_packet(0,0,0);与temp = traffic_models.data_packet(0,0,0);的区别 用MATLAB求矩阵程序I1 2 -1 -1 IaI2 = 0 3 3 * IbI3 2 2 2 Ic如上三行三列矩阵,已知[Ia Ib Ic]=[3 4 5],求I1 I2 I3的MATLAB程序 在c51中P1 = temp; temp = _cror_(temp,1);为什么要用temp而不直接用P1 matlab temp=array(1:2,1:2); [rows,cols]=find(temp==max(max(temp)));是什么意思 temp=array(1:2,1:2);[rows,cols]=find(temp==max(max(temp))); 改错.下列程序中有三个错误,按原来程序的计算要求,纠正其错误如题 #include #include main() { char *name[5]={ “FXPRESSION”,“VARIABLE”,“STATEMENT”,“BLOCK”,“FUNCTION” }; char temp; int i; temp=name[0]; for 请问这个matlaB程序是什么意思?function [value,position] = mymax (x)msg = nargchk (1,1,nargin);error (msg);value = x (1);temp = 1;for ii = 2 :length (x)if value < x (ii)value = x (ii);temp = ii;endendif nargout > 1position = temp;end matlab 提高函数速度temp=[];for j=1:8:121part=bin2dec(data(j:j+7));temp=[temp,part];end这样的几行代码 让我的程序很慢 因为外面还有很大的for循环.请问如何优化,或怎么改成向量来处理这几行代码.data是一 C语言程序中temp是什么意思啊!比如#includestdio.hvoid main(){int i,j,temp,arrnum=[5]={23,9,90,250,16};.temp和arrnum=[5]={23,9,90,250,temp如何运用啊!arrnum是不是定义数组的吗! matlab中编写程序 f(x)=0.5x,x matlab 程序wav_normal(m:m+fs*delay(i)-1)=temp;这里面的delay是社么东西啊?如题最好能给我解释一下这句的详细意思.^▼^ 一段C#程序中 SB.Append(String.Format({0:X2} ,temp)); 最好能有具体例子 在C语言中>>是什么意思?如temp=~((temp>>4)|0xF0); i=uint8(zeros(X,Y,3));MATLAB语句解析[X,Y]=size(temp);i=uint8(zeros(X,Y,3));i(:,:,1)=uint8(temp);i(:,:,2)=uint8(temp);i(:,:,3)=uint8(temp);