How can I create a matrix with combination of some other matrix elemenst dynamicaly in a loop
1 回表示 (過去 30 日間)
古いコメントを表示
Dear Friends
Need an emergency help. it is a pleasure to get any ideas to solve the problem.
discription:
I have a dynamic code which generate some vectors with different size of members like bellow:
The counter is vary from 2 to a unknown value
in loop 1, I have V1, V2 where V1=( 1 2 3), V2=(4, 5)
and Now I want to create a matrix M=[ 1 4;1 5; 2 4; 2 5; 3 4; 3 5]
in the loop 2 the other vector as V3 =(6 7 8) is added to the sysytem and now I want new
M=[ 1 4 6;
1 4 7;
1 4 8;
1 5 6;
1 5 7;
....
3 5 7;
3 5 8]
In the next loop V4 is generrate and if V4=( 9 10) new M should be the combination of all elements of V1, V2, V3, V4
M=[ 1 4 6 9;
1 4 6 10 ;
....]
採用された回答
Bruno Luong
2019 年 7 月 16 日
編集済み: Bruno Luong
2019 年 7 月 16 日
V = {[1 2 3] [4 5] [6 7 8] [9 10]};
M = zeros(1,0);
n = cell(0);
for k=1:length(V)
Vk = V{k}; % replace by your dynamic generation
Vk = Vk(:);
m = size(M,1);
n{k} = 1;
n{1} = size(Vk,1);
M = [repelem(M, n{:}), repmat(Vk,[m 1])];
% do something with the updated M ...
M
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!