MATLAB: Inserting vector to a mxn Matrix

matrix manipulation

I want to insert vector A iteratively in mxn Matrix and in the last column I want to insert a double value. Each time A and constant are changing. E.g. in first iterating A=[1 2 2 4 5] and constant = 3.78. In second iteration A= [3 2 9 8 1]and constant 1.09 and so on… I want this output. [1 2 2 4 5 3.78] [3 2 9 8 1 1.09] [2 3 1 8 1 2.01] and in the end maximum value of last column (double value) is computed. the corresponding array should be displayed. e.g. in the above case max = 3.78 so [1 2 2 4 5] should be displayed How can I do this?

Best Answer

clc; clear all ;
N = 5 ;
iwant = [];
for i = 1:10
A = rand(1,N) ; % your A matrix which changes
k = rand(1,1) ; % your constant which changes
iwant = [[A,k] ; iwant] ; % matrix which you want
end
% Print array knowing maximum value
Max = iwant(3,end) ; % Pick a arbitrary maximum value
% Get the row position for maximum value
[r] = find(iwant(:,end)==Max) ;
% Print tthe array
iwant(r,1:end-1)