matlab中编写for循环语句的问题
请教matlab中有两个120*60的矩阵A1,B1,如果要实现如下的情况:A1(:,1)=A1(:,1)*0.5+B1(:,60)*0.5; B1(:,60)=A1(:,1)*0.5+B1(:,60)*0.5;
A1(:,2)=A1(:,2)*0.5+B1(:,59)*0.5; B1(:,59)=A1(:,2)*0.5+B1(:,59)*0.5;
A1(:,3)=A1(:,3)*0.5+B1(:,58)*0.5; B1(:,58)=A1(:,3)*0.5+B1(:,58)*0.5;
A1(:,4)=A1(:,4)*0.5+B1(:,57)*0.5; B1(:,57)=A1(:,4)*0.5+B1(:,57)*0.5;
……
A1(:,20)=A1(:,4)*0.5+B1(:,41)*0.5; B1(:,41)=A1(:,20)*0.5+B1(:,41)*0.5;
那么用for循环语句该如何编写呢?
回复 楼主 jdsl009 的帖子
for ii=1:20A1(:,ii)=(A1(:,ii)+B1(:,61-ii))/2; B1(:,ii)=(A1(:,ii)+B1(:,61-ii))/2;
end :@D 原来这样 非常感谢 为啥要用循环呢。。。。。 这样也应该可以:
A1(:,1:20)=A1(:,1:20)*0.5+B1(:,60:-1:41)*0.5;
B1(:,60:-1:41)=A1(:,1:20)*0.5+B1(:,60:-1:41)*0.5; 好的 谢谢 原来不要用for循环的:lol 直接
ii=1:20
A1(:,ii)=(A1(:,ii)+B1(:,61-ii))/2; B1(:,ii)=(A1(:,ii)+B1(:,61-ii))/2;
就可以了:@D
页:
[1]