How to index a matrix properly?
- From: Miroslav Pavelka <m.pavelka@xxxxxxxxxx>
- Date: Fri, 31 Aug 2007 18:35:22 +0200
I have a matrix:
A=false(6,6)
A =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I have three pairs of indexes I and J
I=[2 4 6];
J=[1 3 5];
I want the three elements A(2,1), A(4,3) and A(6,5) to be true
What should I do? If I use:
A(I,J)=true;
I receive:
A
A =
0 0 0 0 0 0
1 0 1 0 1 0
0 0 0 0 0 0
1 0 1 0 1 0
0 0 0 0 0 0
1 0 1 0 1 0
But I need only three indexes to be true, not all combinations. What should I do? Is another way how to index the matrix properly?
(I know,.. the solution..
for i=1:1:length(I);
A(I(i),J(i))=true;
end;
But..this solution is time consuming.. do you know something more elegant?
Any advice?
Miroslav Pavelka
.
- Follow-Ups:
- Re: How to index a matrix properly?
- From: Loren Shure
- Re: How to index a matrix properly?
- From: Walter Roberson
- Re: How to index a matrix properly?
- From: Miroslav Pavelka
- Re: How to index a matrix properly?
- Prev by Date: Re: plotting takes too long time
- Next by Date: Re: Initial condition
- Previous by thread: Saving to My Network Places
- Next by thread: Re: How to index a matrix properly?
- Index(es):