append new row in loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi all, i need some solution. Please help. I want to create a function which has L is a matrix 1:11 and return a matrix 40:11 after 40 times of loop.
For example: everytime this function being call, it will carry L and append in row
1st call : L [13 25 15 11 11 14 12 12 10 14 1]
2nd call L [13 25 15 11 11 14 12 12 10 14 2]
....
end result, this function will return:
[13 25 15 11 11 14 12 12 10 14 1]
[13 25 15 11 11 14 12 12 10 14 2]
...
TQIA
function [] = sortmatrix(L)
% append row in matrix
for c = 1:40
b =(L(1,:))
b = L(b; %not sure how to add b into matrix
end
kk = reshape(b,[],11);
%disp(kk)
end
0 commentaires
Réponses (1)
Bhaskar R
le 28 Oct 2019
Its a simple concatanation operation, pass the values e as
L is your constant matrix and number iof loops
as
L = [13 25 15 11 11 14 12 12 10 14];
nLoops = 40;
Then execute your function
function result_mat = sortmatrix(L, nLoops)
% here nLoops is 40 times of loop and L is constant matrix
% E.g L = [13 25 15 11 11 14 12 12 10 14] and nLoops = 40
result_mat = zeros(nLoops, size(L,2)+1); % Initialize result matrix
for ii = 1:nLoops
result_mat(ii,:) = [L, ii]; % concatante loop value to result matrix
end
end
The variable result_mat is your required matrix
1 commentaire
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!