# Condition

1 visualizzazione (ultimi 30 giorni)
Manpreet Kapoor il 11 Mag 2011
Hi,
I have a query.
Generally relational operators are used to check whether some condition is true. i.e. it returns a logical vector. Is it possible that the new vector has the same values as the original vector (based on some conditions). For eg, Suppose there is a vector with 10 elements [say (1,3,2,1,4,6,7,8,5,2)]and i put a condition that the new vector is formed such that it has elements which are only less say 5. How is that possible.?
Regards
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Manpreet Kapoor il 11 Mag 2011
I just need one more clarification. Can the size of the vector be decreased such that it neglects the values which are now 0.
i.e. suppose my vector length was earlier 10 and now the new vector has only 7 elements because rest of them are more than 5.

Accedi per commentare.

### Risposta accettata

Andrei Bobrov il 11 Mag 2011
just
vnew = v.*(v<5)
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Manpreet Kapoor il 11 Mag 2011
I just need one more clarification. Can the size of the vector be decreased such that it neglects the values which are now 0.
i.e. suppose my vector length was earlier 10 and now the new vector has only 7 elements because rest of them are more than 5.

Accedi per commentare.

### Più risposte (1)

Adrien Leygue il 11 Mag 2011
Try this:
A = rand(1,10);
B = A(A<0.5);
C = zeros(size(A));
I think this could provide some answer.
A.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by