# How to assign a number to an array of double?

2 Ansichten (letzte 30 Tage)
JFz am 18 Jul. 2018
Kommentiert: JFz am 18 Jul. 2018
Hi, I have an array of doubles a. It has integers from 0 to 6. I want to keep the 0s and 2s, but change all other numbers to be 1. So I use a(~isequal(a,2) && ~isequal(a,0)) = 1; No error messages but the content a is still the same. Why? Thanks!
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

James Tursa am 18 Jul. 2018
The isequal() function returns either a logical 0 or 1 depending on if the two arguments are equal. It does not return an element-by-element comparison. To do the element-by-element operation, use the == operator instead. Also use the element-by-element operator & instead of the logical operator &&. E.g.,
a(~(a==2) & ~(a==0)) = 1;
##### 1 KommentarKeine anzeigenKeine ausblenden
JFz am 18 Jul. 2018
Thanks!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Get Started with MATLAB in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by