Filter löschen
Filter löschen

help with a matlab code

5 Ansichten (letzte 30 Tage)
roshan varkey
roshan varkey am 4 Dez. 2013
Beantwortet: Walter Roberson am 4 Dez. 2013
i have this particular code:
Board = zeros(10);
ALPHArange = 'A':'J';
Drow = ALPHArange(randi(numel(ALPHArange)));
Dcol = randi(9,1,1);
idx = find(ismember(ALPHArange, Drow));
Board(idx, Dcol:Dcol + 1) = 2;
idx = find(ismember(ALPHArange, Drow));
this line should find the index of Drow in array ALPHArange. For example, if randomly choosen alphabet is 'E' then idx will have value 5, for 'C' value 3 and so on and it will be your row number in the next line
Board(idx, Dcol:Dcol + 1) = 2;
but when i tried this,the value of .......idx = find(ismember(ALPHArange, Drow))........... is always 1,even when the randomly choosen alphabet is 'E' or 'F'........ so, all the points i try to put into matrix always ends up in the first row.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Dez. 2013
[tf, idx] = ismember(Drow, ALPHArange);

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays 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