replacing different elements in a matrix according to different conditions
Afficher commentaires plus anciens
Hi
I have an array which contains integers from 0 to 5. Now I want to replace all 5s with a 0, all 0 with a 5, the 2s with a 4 and vice versa and the 3 would not be changed. I know that I could do that with several nested if loops - but is there a faster/smarter way?
6 commentaires
per isakson
le 11 Mai 2015
... and 1 would not change?
Joseph Cheng
le 11 Mai 2015
What do you do with 1's
MiauMiau
le 11 Mai 2015
Sebastian Castro
le 11 Mai 2015
Based on those rules, you could "cheat" and do this completely without logic:
out = 5 - in
MiauMiau
le 11 Mai 2015
Image Analyst
le 12 Mai 2015
There is a general function that lets you map any integer into any other number you want in a single line of code. It's general, not just "5-in" which coincidentally happens to work for this particular case. However based on your request - the only one I've ever gotten on over 15,000 questions answered - I won't answer.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!