Insert number 1 to certain column and row in a matrices
1 view (last 30 days)
Show older comments
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 Comment
Stephen23
on 25 Nov 2018
Do NOT use table as a variable name, as this is the name of an important inbuilt function.
Answers (1)
Stephen23
on 25 Nov 2018
Edited: Stephen23
on 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
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!