creating a 8x8 matrix with only -1

7 visualizaciones (últimos 30 días)
Aimee
Aimee el 27 de Oct. de 2024
Comentada: Aimee el 10 de Dic. de 2024
i want to create a 8x8 matrix withn only the number -1 how do i do it?

Respuestas (3)

Torsten
Torsten el 27 de Oct. de 2024
Movida: Torsten el 27 de Oct. de 2024
Use "ones" to build a matrix of ones and multiply it by (-1).
  1 comentario
Walter Roberson
Walter Roberson el 28 de Oct. de 2024
You have to be careful to build up the 8 x 8 size for the ones() call, out of pure -1's. It is certainly possible to do.

Iniciar sesión para comentar.


埃博拉酱
埃博拉酱 el 28 de Oct. de 2024
Editada: 埃博拉酱 el 29 de Oct. de 2024
-ones(8)
Append at 20241029 as a Cody challenge:
rand(single('('-' '))
%You don't even need -1 in your code. This can be applied to any challenge that has a limit on the number that appears in the code.
%If you're okay with using characters that aren't on your keyboard, you can even just use a Backspace character (U+0008).
  6 comentarios
Walter Roberson
Walter Roberson el 29 de Oct. de 2024
The + are not needed
A = -ones((-1 -1 -1 -1)*(-1 -1))
A = 8×8
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
DGM
DGM el 29 de Oct. de 2024
D'oh!
I must have had my blinders on when I was coming up with that.

Iniciar sesión para comentar.


Aimee
Aimee el 29 de Oct. de 2024
hey guys thanks for all the help i got it eventuallyt with the code A = -ones(8,8). just incase anyone sees this and need help in the future.
  7 comentarios
DGM
DGM el 30 de Oct. de 2024
Editada: DGM el 30 de Oct. de 2024
As a counterexample, "create fire with only flint and steel" typically does not imply that the fire contains either flint or steel. Maybe we're all wrong to be creating a matrix full of -1.
Aimee
Aimee el 10 de Dic. de 2024
no youre correct i wanted an 8x8 matrix where the only elements were -1 i managed it eventually with the formula i used above though.

Iniciar sesión para comentar.

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by