Changing the number of rows in a vector by adding repeated rows

4 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 2 月 15 日
回答済み: Kevin Holly 2023 年 2 月 15 日
I have a vector V [76x3 double] and I want to make it V1 [1022x3 double].
I want to get the vector V1 in the following way:
-> rows 1:76 are the rows of vector V
-> rows 77:1022 are the rows of vector V placed randomly
How can it be obtained?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 2 月 15 日
What do you mean by "missing rows"? Rows with zeros or nans? or otherwise? Please specify.
Do you want to add rows after the 76 rows or are some rows inbetween as well?
Alberto Acri
Alberto Acri 2023 年 2 月 15 日
I have modified the question. I hope it is clearer now.

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 2 月 15 日
編集済み: Dyuman Joshi 2023 年 2 月 15 日
%V1 is 76x3 double
%random data
V1 = rand(76,3);
s = size(V1,1);
n = 1022;
%randomly sorted row indices from 1 to 76 to append
idx = randi(s,n-s,1)
idx = 946×1
66 44 65 72 10 21 47 41 8 74
%appending rows according to the indices
V1(s+1:n,:) = V1(idx,:);
size(V1)
ans = 1×2
1022 3

その他の回答 (1 件)

Kevin Holly
Kevin Holly 2023 年 2 月 15 日
V = rand(76,3);
V1 = zeros(1064,3);
V1(1:76,:) = V;
for ii=1:13
index = randperm(76);
V1(76*ii+1:76*ii+76,:)= V(index,:);
end
V1 = V1(1:1022,:)
V1 = 1022×3
0.5613 0.6987 0.4500 0.9735 0.3625 0.3413 0.5039 0.4922 0.1920 0.9099 0.5943 0.0964 0.1295 0.0884 0.6340 0.0908 0.7025 0.3233 0.8137 0.0421 0.7189 0.9342 0.5742 0.5566 0.0371 0.4320 0.9536 0.7889 0.8865 0.2672

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by