Counting in a Matrix
Show older comments
Hi all,
I have a 3 by 7 matrix as following:
g =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
if I write
g(9) = 1
I get:
g =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 0 0 0 0
when actually want g(9) = 1 to be:
g =
0 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 0 0 0 0 0
or in other terms, instead of counting down columns for 1,2,3,4,5...... I want to count across rows. Is there an option in Matlab to change this function.
Thank you in advance.
Matthew.
Accepted Answer
More Answers (1)
Image Analyst
on 26 May 2013
0 votes
You can transpose it, change it, and transpose it. But why not just use row, column indexing? There are also functions subs2ind() and ind2subs() that you might be interested in.
Categories
Find more on Matrix Indexing 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!