how do I switch values in a random matrix without using witch or any kind of loop?

1 view (last 30 days)
I need to change this matrix
x = round(0+(4)*rand(20,30)) which contains the values 0,1,2,3,4 to the matrix y - - if - x(i,j)=0 than y(i,j)=5
if x(i,j)=1 than y(i,j)=4
if x(i,j)=2 than y(i,j)=3
if x(i,j)=3 than y(i,j)=2
if x(i,j)=4 than y(i,j)=1
this sould be done without using any kind of loops any ideas?

Accepted Answer

Matt J
Matt J on 10 Nov 2013
Edited: Matt J on 10 Nov 2013
y=5-x;

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!