Find the max between two arrays and then concatenate the cells of the max array

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:

Let us consider 2 arrays tab1 and tab2. (are two arrays of matrices)

First step: The maximum between these two arrays will be tab3

Second step: i want to concatenate the cells of tab3

Here is my MATLAB CODE:

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

Answers


here's one way to do it:

x=max(cell2mat(tab1), cell2mat(tab2))

Need Your Help

Asp.net multilingual web application - localization

asp.net localization resources

What's your opinion for the best possible way to build asp.net multilingual localized web application (only UI localization of string resources). Especially this two things:

While statement not stopping when it should

python while-loop

this is my first post here. I'm new to Python and programming in general so I'm not sure where I went wrong. This is a solution I came up with to Problem #52 on Project Euler (I know it's probably ...