creating a 8x8 matrix with only -1

121 Ansichten (letzte 30 Tage)
Aimee
Aimee am 27 Okt. 2024 um 23:13
Bearbeitet: DGM am 30 Okt. 2024 um 22:35
i want to create a 8x8 matrix withn only the number -1 how do i do it?

Antworten (3)

Torsten
Torsten am 27 Okt. 2024 um 23:19
Verschoben: Torsten am 27 Okt. 2024 um 23:19
Use "ones" to build a matrix of ones and multiply it by (-1).
  1 Kommentar
Walter Roberson
Walter Roberson am 28 Okt. 2024 um 0:21
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.

Melden Sie sich an, um zu kommentieren.


埃博拉酱
埃博拉酱 am 28 Okt. 2024 um 13:46
Bearbeitet: 埃博拉酱 am 29 Okt. 2024 um 0:26
-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 Kommentare
Walter Roberson
Walter Roberson am 29 Okt. 2024 um 1:14
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 am 29 Okt. 2024 um 13:31
D'oh!
I must have had my blinders on when I was coming up with that.

Melden Sie sich an, um zu kommentieren.


Aimee
Aimee am 29 Okt. 2024 um 13:14
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.
  6 Kommentare
Torsten
Torsten am 30 Okt. 2024 um 15:05
I'm not a native speaker, but isn't the usual interpretation of "creating a 8x8 matrix with only -1":
create a 8x8 matrix which has only -1's as elements
?
DGM
DGM am 30 Okt. 2024 um 22:29
Bearbeitet: DGM am 30 Okt. 2024 um 22:35
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by