Changing the number of rows in a vector by adding repeated rows
4 次查看(过去 30 天)
显示 更早的评论
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
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?
采纳的回答
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)
%appending rows according to the indices
V1(s+1:n,:) = V1(idx,:);
size(V1)
0 个评论
更多回答(1 个)
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,:)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!