Effacer les filtres
Effacer les filtres

How to compare a vector A of real numbers with a vector of zeros using equalities and inequalities?

2 vues (au cours des 30 derniers jours)
Hi, I have a vector A mx1 which should be compared with a mx1 vector of zeros. In particular: for the first n<m elements I want to obtain 1 if they are equal to zero; for the remaining m-n elements I want to obtain 1 if they are less than or equal to zero. I prefer no loops. For example:
m=5;
n=2;
A=[0; 1; -3; 1; 5];
I want to get
C=[1;0;1;0;0];
Thanks

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 9 Déc 2013
C = [A(1:n) == 0;A(n+1:end) <= 0];

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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