append new row in loop
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Bhaskar R
2019년 10월 28일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!