0
我为此编写了一个Matlab代码,它运行良好。但我想知道它是否优化。如果不是这样,所以我需要你的帮助,首先写一个更优化的代码..查找两个数组之间的最大值,然后连接最大数组的单元格
,我想解释一下我的工作理念:
让我们考虑2个阵列TAB1和TAB2。 (是矩阵的两个阵列)
第一步:这两个阵列之间的最大将是TAB3
第二步:ⅰ想连接TAB3的细胞
这里是我的MATLAB代码:
clear all;
close all;
clc;
I1=[1 2 3
4 5 6]
B1=[5 6 4
3 4 2]
c1=[2 5 4
1 2 5]
d1=[2 8 9
0 1 2]
I2=[4 7 6
3 2 4]
B2=[4 6 5
2 3 5]
c2=[6 7 2
1 7 6]
d2=[8 6 3
3 6 5]
%tab1 and tab2
tab1={I1,B1
c1,d1}
tab2={I2,B2
c2,d2}
[n,m]=size(tab1) % or [n,m]=size(tab2) because tab1 and tab2 have the same size
%find the maximum between tab1 and tab2 and then put the result into tab3
for i=1:n
for j=1:m
tab3{i,j}=max(tab1{i,j},tab2{i,j});
end
end
for i=1:n
if(i==1)
x=cat(2,tab3{i,1:m});
else
y=cat(1,x,cat(2,tab3{i,1:m}));
x=y;
end
end
%display the concatenation
x