找到两个数组之间的最大值,然后连接最大数组的单元格 [英] Find the max between two arrays and then concatenate the cells of the max array
本文介绍了找到两个数组之间的最大值,然后连接最大数组的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为此编写了一个Matlab代码,效果很好.但我想知道它是否最佳.如果没有,那么我需要您的帮助来编写更优化的代码.
I wrote a Matlab code for that and it works well. But i would like to know if it's optimal or not. If not, so i need your help to write a more optimal code..
首先,我想解释一下我的作品的概念:
Firstly, i would like to explain the concept of my work:
让我们考虑两个数组 tab1 和 tab2 . (是两个矩阵数组)
Let us consider 2 arrays tab1 and tab2. (are two arrays of matrices)
第一步 :这两个数组之间的最大值为tab3
First step: The maximum between these two arrays will be tab3
第二步:我要串联tab3的单元格
Second step: i want to concatenate the cells of 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
推荐答案
这是一种解决方法:
x=max(cell2mat(tab1), cell2mat(tab2))
这篇关于找到两个数组之间的最大值,然后连接最大数组的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文