# Vector inside another vector

13 ビュー (過去 30 日間)
José Campelo 2019 年 5 月 21 日
コメント済み: madhan ravi 2019 年 5 月 21 日
Hi! I have a vector S = [0 1 2 3 4 ... 30]' and now i want to create another vector U that is equal to 0 if K<S and equal to S if K>=S. In my exercise K=15.
I did this:
U1=zeros(30,1);
U1(15,30)=S;

#### 3 件のコメント

Adam Danz 2019 年 5 月 21 日
So U will always be a column vector the same size as 'S' and it will always be either full of 0s or it will match the "S" vector (depending on the value of K which will always be a single number (scalar)). Is that correct?
Alex Mcaulley 2019 年 5 月 21 日
Your problem is not difficult. You just need to take a look to logical indexing in Matlab. For example:
José Campelo 2019 年 5 月 21 日
Correct. Basically what I want is that U be a column with 0 until the 14th position and then 15, 16, 17 etc until 30.

サインイン to comment.

### 採用された回答

Adam Danz 2019 年 5 月 21 日
S =(0:30)';
k = 15;
U = S .* (S>=k);

#### 0 件のコメント

サインイン to comment.

### その他の回答 (1 件)

madhan ravi 2019 年 5 月 21 日

People don’t do homeworks here. Index K>=S to U1 lhs and S rhs by equating against each other. Since it’s your homework see Alex’s links above and experiment.

#### 2 件のコメント

Adam Danz 2019 年 5 月 21 日
My homework detectors didn't go off on this one.
madhan ravi 2019 年 5 月 21 日
XD sometimes it doesn’t even in mine, maybe a bug xd.

サインイン to comment.

サインイン してこの質問に回答します。

Translated by