필터 지우기
필터 지우기

Counting in a Matrix

조회 수: 1 (최근 30일)
Matthew
Matthew 2013년 5월 26일
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.

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 26일
No, there is no option to change the order of the dimensions.
If there is an especially good reason to count across, you could use
Tg = g.';
Tg(9) = 1;
g = Tg.';
There are also calculations that can be done to switch between the two orderings, but my algebra center in my brain is telling me it is the weekend and it wants to sleep in...

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 5월 26일
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.

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by