Finding a range in an array
70 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Rafay Ali
il 27 Mag 2019
Modificato: madhan ravi
il 27 Mag 2019
I have an array of 8000 values. I want to find a range of particular values say for example the values which are between 20 - 25.6 should be multiplied by -1 but the values should be in changed in the same array. I am currently using a the find nested in an if but somehow I cannot store it in the same array.
Risposta accettata
madhan ravi
il 27 Mag 2019
Modificato: madhan ravi
il 27 Mag 2019
idx = (array>=20) & (array<=25.6);
array(idx) = -array(idx)
2 Commenti
madhan ravi
il 27 Mag 2019
Modificato: madhan ravi
il 27 Mag 2019
I suggest you to do MATLAB onramp course to cover the basics of MATLAB.
idx = (array>=20) & (array<=25.6); % using this as indices is already much more efficient than find()
indices = find(idx) % this would give you the indices where the condition satisfies
array(2222 : 2245) = - some_number * array(2222 : 2245)
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!