# How can I generate voctors of double values from another bector?

조회 수: 1 (최근 30일)
Mira le 2021년 4월 27일
댓글: Steven Lord 2021년 4월 27일
Hello everyone, My issue here is , I have a vector of double values v1=[12,3459,450,......,567], I want to generate many vectors that contains either zero or values from v1 that are chosen randomly,and the length of new vector is m=120 for example
Thank you
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Jonas 2021년 4월 27일
편집: Jonas 2021년 4월 27일
you can generate a vector from v1 with length 120 if you call v2=datasample(v1,120), but then there are no zero values in there (except if v1 contains zero values). you could then set random entries to zero again if you want to
Steven Lord 2021년 4월 27일
Do you want to select elements of v1 with or without replacement?
How do you want to add 0 values to the result?
1. Each element of the result is either the corresponding element of v1 or is 0. If this option, with what probability do you want to replace the element of v1 with 0?
2. Even if 0 is not an element of v1, it is a candidate to be selected for one element of the result, with an equal probability of being selected as any element of v1.
3. Select some number of elements of v1. Add enough 0 values to have 120 total elements, then shuffle the 120 elements.
4. Some other approach (if so what?)

댓글을 달려면 로그인하십시오.

### 답변 (1개)

David Hill 2021년 4월 27일
v2=[0,v1];
newVector=v2(randi(length(v2),1,m));
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Mira le 2021년 4월 27일
V2=[0,v1] doen t work it s an error It says that Dimension of matrices being concatenated are not consistent

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

R2017a

### Community Treasure Hunt

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

Start Hunting!

Translated by