How to fix the range of a variable?

조회 수: 2 (최근 30일)
Sayantan Saha
Sayantan Saha 2021년 4월 20일
답변: David Hill 2021년 4월 20일
problem.CostFunction = @(x) MinPe(x, Biv, Cell);
I have this Matlab fucntion where x is a variable. The value of x is an array of 24 digits which only consist 0's and 1's. x is automatically selecting this input.
I want expand the range of x i.e. the array should not only consists 0's and 1's but within the range of 0 to 3.
for example, in case of 5 digits:
x is taking a value like [0 1 0 1 1]
but x should take a value like [0 3 2 1 3]
Could you please tell me the process to do it?
  댓글 수: 1
Jonas
Jonas 2021년 4월 20일
is this a question of counting system, so you want to e.g. convert the binary number system (000, 001, 010, 011, ...) to the system which can count up to three (000, 001, 002, 003, 010, 011, ...)?

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

답변 (1개)

David Hill
David Hill 2021년 4월 20일
Not clear what the question is, but if you just want to randomly sectect 24 digits from 0-3, then:
x=randi(4,1,24)-1;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by