Chaging the outupt integers

I have a code here
M=256;
N=256
A=fix(2*rand(M,N));
And right now the output either is zero or one. Well I want the output to be either 1 or -1. Can anyone help me as to how to change this. Thank you, I'm quite new to matlab.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
Editada: Azzi Abdelmalek el 25 de Feb. de 2013

0 votos

M=256;
N=256
A=fix(2*rand(M,N));
A(A==0)=-1

2 comentarios

Jakub
Jakub el 25 de Feb. de 2013
Sweet thank you, it works perfectly :)
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
Editada: Azzi Abdelmalek el 25 de Feb. de 2013
You can also use
A=sign(rand(M,N)-0.5)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by