Create a matrix whereas values can be -180 0 or 200

Hello
Is like the title says: i would be able to create a certain matrix 1:24 where i can only have -180, 0 or 200 sort randomly.
P.E.
[-180 200 0 0 0 200 200 -180 -180 0 ....]
Thanks in advance

 채택된 답변

Laura Proctor
Laura Proctor 2012년 12월 18일

1 개 추천

I'm sure there's a more elegant solution, but here's one:
x = randi(3,1,24)-1;
x(x==1) = -180;
x(x==2) = 200;

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 12월 18일

1 개 추천

Try this:
a = int16(randi(3, 1, 24))
a(a==1) = -180;
a(a==2) = -0;
a(a==3) = -200;

댓글 수: 1

For a more general solution you can use intlut(), in the Image Processing Toolbox.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by