replacing different elements in a matrix according to different conditions
이전 댓글 표시
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
per isakson
2015년 5월 11일
... and 1 would not change?
Joseph Cheng
2015년 5월 11일
What do you do with 1's
MiauMiau
2015년 5월 11일
Sebastian Castro
2015년 5월 11일
Based on those rules, you could "cheat" and do this completely without logic:
out = 5 - in
MiauMiau
2015년 5월 11일
Image Analyst
2015년 5월 12일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!