フィルターのクリア

Combine multiple vectors into specific locations of one matrix

2 ビュー (過去 30 日間)
Yu Takahashi
Yu Takahashi 2021 年 2 月 7 日
コメント済み: Yu Takahashi 2021 年 2 月 9 日
Dear members
In short, as indicated by the title, I was trying to combine 20 vectors into one new matrix i.e., 10 each generated by condition_A and condition_B using a for loop. Specifically, assigning all condition_As to the second column, and all condition_Bs to the third column of a new matrix.
for n = 1: 10
% a
condition_a = [ repmat(23,1,6) repmat(99,1,6) ];
condition_A = condition_a(randperm(length(condition_a)));%Vector a here %this is to randomize the order of the numbers
% b
condition_b = [111 112 127 123 211 218 221 222 311 312 321 333 ];
condition_B = condition_b(randperm(length(condition_b)));% Vector b here
% other irrelevant stuff down below
end
I apologize if this is a naive question, thanks in advance.
Please let me know if more information is needed.
  1 件のコメント
Yu Takahashi
Yu Takahashi 2021 年 2 月 7 日
編集済み: Yu Takahashi 2021 年 2 月 7 日
In other words, I was trying to achieve something like this
For the new matrix :
First column : (empty)
Second column : 1st condition_A, 2nd condition_A, 3rd condition_A ... 10th condition_A
Third column : 1st condition_B, 2nd condition_B, 3rd condition_B ... 10th condition_B

サインインしてコメントする。

採用された回答

David Hill
David Hill 2021 年 2 月 7 日
You can't leave the first column empty. Why not put zeros in?
a=[6 6 6 6 6 6 99 99 99 99 99 99]';
b=[111 112 127 123 211 218 221 222 311 312 321 333 ]';
L=length(a);
m=zeros(10*L,3);
for k=1:10
m(L*(k-1)+1:k*L,2)=a(randperm(L));
m(L*(k-1)+1:k*L,3)=b(randperm(L));
end
  1 件のコメント
Yu Takahashi
Yu Takahashi 2021 年 2 月 9 日
thanks for your help! this is exactly what i was looking for

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by