Vector inside another vector

2 vues (au cours des 30 derniers jours)
José Campelo
José Campelo le 21 Mai 2019
Commenté : madhan ravi le 21 Mai 2019
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;
Can you please help me? Thanks
  3 commentaires
Alex Mcaulley
Alex Mcaulley le 21 Mai 2019
Your problem is not difficult. You just need to take a look to logical indexing in Matlab. For example:
José Campelo
José Campelo le 21 Mai 2019
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.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 21 Mai 2019
S =(0:30)';
k = 15;
U = S .* (S>=k);

Plus de réponses (1)

madhan ravi
madhan ravi le 21 Mai 2019
Modifié(e) : madhan ravi le 21 Mai 2019
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 commentaires
Adam Danz
Adam Danz le 21 Mai 2019
My homework detectors didn't go off on this one.
madhan ravi
madhan ravi le 21 Mai 2019
XD sometimes it doesn’t even in mine, maybe a bug xd.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by