Insert number 1 to certain column and row in a matrices

1 回表示 (過去 30 日間)
fyza affandi
fyza affandi 2018 年 11 月 25 日
編集済み: Stephen23 2018 年 11 月 25 日
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 件のコメント
Stephen23
Stephen23 2018 年 11 月 25 日
Do NOT use table as a variable name, as this is the name of an important inbuilt function.

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2018 年 11 月 25 日
編集済み: Stephen23 2018 年 11 月 25 日
>> 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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by