MATLAB: Newbie help for matlab

MATLABmatlab function

how do i write a function that has two 3×3 input matrices and in output it gives new matrix that contains the rows of the input that has the least sum .I.e. a=[1 2 3;2 3 4; 3 4 5] and b=[1 2 3;2 3 4; 3 4 5] then print c=[1 2 3;1 2 3] . I have the logic in my head but i can't code it in matlab since i have only 1 lesson on it. Thanks

Best Answer

See if this does what you want:
a=[1 2 3;2 3 4; 3 4 5];
b=[1 2 3;2 3 4; 3 4 5];
sa = sum(a,2);
sb = sum(b,2);
mab = [a; b];
sab = [sa; sb];
[srtab,ix] = sort(sab,'ascend');
c = mab(ix(1:2),:)
producing:
c =
1 2 3
1 2 3