Effacer les filtres
Effacer les filtres

Insert number 1 to certain column and row in a matrices

4 vues (au cours des 30 derniers jours)
fyza affandi
fyza affandi le 25 Nov 2018
Modifié(e) : Stephen23 le 25 Nov 2018
I have 3D (9x10x2) matrices named Table.
table = zeros(9,10,2); %Create 3d table
I want to insert 1 like below
table (:,:,1)=
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 1 1 0
table (:,:,2)=
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
5 ones in table (:,:,1) and 1 ones in table (:, :,2). I have done the coding but I still cant get the answer
[row,col,page]=size(table);
i=0;
for nC= 0:2
for nR= 0:1
table(col-nC,row-nR-i,1)=1;
end
i=i+1;
end
I hope you guys can help me. Thank you
  1 commentaire
Stephen23
Stephen23 le 25 Nov 2018
Do NOT use table as a variable name, as this is the name of an important inbuilt function.

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 25 Nov 2018
Modifié(e) : Stephen23 le 25 Nov 2018
>> t = zeros(9,10,2);
>> t([43,53,62,72,81,97]) = 1
t(:,:,1) =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 1 1 0
t(:,:,2) =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by