Filter löschen
Filter löschen

How to change array elements?

1 Ansicht (letzte 30 Tage)
Alex
Alex am 22 Mai 2013
Kommentiert: ofek berdah am 24 Mär. 2021
I'm making a tic-tac-toe game and wish to display a 3x3 array with "X"s "O"s and spaces from an array the has -1's 1's and 0's from inputs, how would I go about doing that? I want to basically convert and input matrix to a display matrix

Akzeptierte Antwort

David Sanchez
David Sanchez am 22 Mai 2013
I hope the following code is of help:
% example matrix
M=[-1 1 0;
1 0 -1;
0 0 1];
D_1_ = find(M==-1);
D_0 = find(M==0);
D_1 = find(M==1);
D(D_0) = 'O';
D(D_1) = 'X';
D(D_1_) = ' ';
F = [D(1:3);D(4:6);D(7:9)]';
N=cell(3,3);
% to display spaces, use horizcat
for col = 1:3
for row = 1:3
N{col,row} = horzcat(F(col,row),' ');
end
end
disp(N)
  2 Kommentare
Alex
Alex am 22 Mai 2013
Thankyou :)
ofek berdah
ofek berdah am 24 Mär. 2021
What does it mean cell?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by