Inserting vector to a mxn Matrix
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Here is the simple solution without find:
% preallocate matrix and vector:
mat = NaN(3,5);
vec = NaN(3,1);
% add your values in a loop:
mat(1,:) = [1,2,2,4,5];
vec(1,1) = 3.78;
mat(2,:) = [3,2,9,8,1];
vec(2,1) = 1.09;
mat(3,:) = [2,3,1,8,1];
vec(3,1) = 2.01;
% find maximum and display:
[val,idx] = max(vec);
disp(mat(idx,:))
The code displays the corresponding row of mat in the command window:
1 2 2 4 5
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!