Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Regarding Matrrix Indexing

Subject: Regarding Matrrix Indexing

From: Parag Chandakkar

Date: 28 Nov, 2011 17:22:16

Message: 1 of 20

Hi,

Suppose I have a matrix "A" of 10x10 of all zeros. Now, I have another
matrix say,

I=[1 7; 2 1; 3 3; 4 5]. How do I make elements of A one at position
indicated by elements by I?
That means, matrix "A" should have ones at positions (1,7) , (2,1),
(3,3), (4,5).
I want to avoid for loops since I have to do this for a bigger matrix.

Thanks.
- Parag S. Chandakkar.

Subject: Regarding Matrrix Indexing

From: Nasser M. Abbasi

Date: 28 Nov, 2011 17:48:18

Message: 2 of 20

On 11/28/2011 11:22 AM, Parag Chandakkar wrote:
> Hi,
>
> Suppose I have a matrix "A" of 10x10 of all zeros. Now, I have another
> matrix say,
>
> I=[1 7; 2 1; 3 3; 4 5]. How do I make elements of A one at position
> indicated by elements by I?
> That means, matrix "A" should have ones at positions (1,7) , (2,1),
> (3,3), (4,5).
> I want to avoid for loops since I have to do this for a bigger matrix.
>
> Thanks.
> - Parag S. Chandakkar.

may be

----------------
A=zeros(10);
siz=size(A);
I=[1 7; 2 1; 3 3; 4 5];
A(sub2ind(siz,I(:,1),I(:,2)))=1
-------------------------

A =

      0 0 0 0 0 0 1 0 0 0
      1 0 0 0 0 0 0 0 0 0
      0 0 1 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 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0

--Nasser

Subject: Regarding Matrrix Indexing

From: Parag S. Chandakkar

Date: 28 Nov, 2011 18:05:08

Message: 3 of 20

On Nov 28, 10:48 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 11/28/2011 11:22 AM, Parag Chandakkar wrote:
>
> > Hi,
>
> > Suppose I have a matrix "A" of 10x10 of all zeros. Now, I have another
> > matrix say,
>
> > I=[1 7; 2 1; 3 3; 4 5]. How do I make elements of A one at position
> > indicated by elements by I?
> > That means, matrix "A" should have ones at positions (1,7) , (2,1),
> > (3,3), (4,5).
> > I want to avoid for loops since I have to do this for a bigger matrix.
>
> > Thanks.
> > - Parag S. Chandakkar.
>
> may be
>
> ----------------
> A=zeros(10);
> siz=size(A);
> I=[1 7; 2 1; 3 3; 4 5];
> A(sub2ind(siz,I(:,1),I(:,2)))=1
> -------------------------
>
> A =
>
>       0     0     0     0     0     0     1     0     0     0
>       1     0     0     0     0     0     0     0     0     0
>       0     0     1     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     0     0     0     0     0
>       0     0     0     0     0     0     0     0     0     0
>       0     0     0     0     0     0     0     0     0     0
>       0     0     0     0     0     0     0     0     0     0
>
> --Nasser

Thank you very much. It works.
- Parag S. Chandakkar.

Subject: Regarding Matrrix Indexing

From: dpb

Date: 28 Nov, 2011 19:38:48

Message: 4 of 20

On 11/28/2011 12:05 PM, Parag S. Chandakkar wrote:
> On Nov 28, 10:48 am, "Nasser M. Abbasi"<n...@12000.org> wrote:
>> On 11/28/2011 11:22 AM, Parag Chandakkar wrote:
>>
>>> Hi,
>>
>>> Suppose I have a matrix "A" of 10x10 of all zeros. Now, I have another
>>> matrix say,
>>
>>> I=[1 7; 2 1; 3 3; 4 5]. How do I make elements of A one at position
>>> indicated by elements by I?
...

>> A=zeros(10);
>> siz=size(A);
>> I=[1 7; 2 1; 3 3; 4 5];
>> A(sub2ind(siz,I(:,1),I(:,2)))=1
>> -------------------------
...

> Thank you very much. It works.
...

So would

A(I)=1;

Didn't you even try it first?

If not, it's time for "Getting Started" section on matrices and
operations; it's key to using Matlab effectively.

--

Subject: Regarding Matrrix Indexing

From: Nasser M. Abbasi

Date: 28 Nov, 2011 19:54:20

Message: 5 of 20

On 11/28/2011 1:38 PM, dpb wrote:
> On 11/28/2011 12:05 PM, Parag S. Chandakkar wrote:
>> On Nov 28, 10:48 am, "Nasser M. Abbasi"<n...@12000.org> wrote:
>>> On 11/28/2011 11:22 AM, Parag Chandakkar wrote:
>>>
>>>> Hi,
>>>
>>>> Suppose I have a matrix "A" of 10x10 of all zeros. Now, I have another
>>>> matrix say,
>>>
>>>> I=[1 7; 2 1; 3 3; 4 5]. How do I make elements of A one at position
>>>> indicated by elements by I?
> ...
>
>>> A=zeros(10);
>>> siz=size(A);
>>> I=[1 7; 2 1; 3 3; 4 5];
>>> A(sub2ind(siz,I(:,1),I(:,2)))=1
>>> -------------------------
> ...
>
>> Thank you very much. It works.
> ...
>


> So would
>
> A(I)=1;
>
> Didn't you even try it first?
>
> If not, it's time for "Getting Started" section on matrices and
> operations; it's key to using Matlab effectively.
>
> --


Are you really sure about that?

on my system, I get:

A=zeros(10);
siz=size(A);
A(I)=1

A =

      1 0 0 0 0 0 0 0 0 0
      1 0 0 0 0 0 0 0 0 0
      1 0 0 0 0 0 0 0 0 0
      1 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
      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

?

Which is not the same as what the OP wanted, which is

A =

      0 0 0 0 0 0 1 0 0 0
      1 0 0 0 0 0 0 0 0 0
      0 0 1 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 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0


--Nasser

Subject: Regarding Matrrix Indexing

From: Matt J

Date: 28 Nov, 2011 19:55:09

Message: 6 of 20

dpb <none@non.net> wrote in message <jb0o04$r2i$2@speranza.aioe.org>...
>
> > Thank you very much. It works.
> ...
>
> So would
>
> A(I)=1;
==========

Don't think so...

Subject: Regarding Matrrix Indexing

From: Roger Stafford

Date: 28 Nov, 2011 20:19:08

Message: 7 of 20

dpb <none@non.net> wrote in message <jb0o04$r2i$2@speranza.aioe.org>...
> So would
>
> A(I)=1;
- - - - - - - -
  I get what Nasser gets, dpb. My system treats the I elements as linear indices.

Roger Stafford

Subject: Regarding Matrrix Indexing

From: dpb

Date: 28 Nov, 2011 22:37:53

Message: 8 of 20

On 11/28/2011 2:19 PM, Roger Stafford wrote:
> dpb <none@non.net> wrote in message <jb0o04$r2i$2@speranza.aioe.org>...
>> So would
>>
>> A(I)=1;
> - - - - - - - -
> I get what Nasser gets, dpb. My system treats the I elements as linear
> indices.

Yeah, that's "my bad" on that-there one, sorry.

It seems like it _should_ work...but doesn't. Don't know precisely why
TMW chose the implementation as they did of A(I(:)) instead of the
literal meaning of the index array elements.

--

Subject: Regarding Matrrix Indexing

From: Steven_Lord

Date: 29 Nov, 2011 15:12:33

Message: 9 of 20



"dpb" <none@non.net> wrote in message news:jb12fv$nlj$1@speranza.aioe.org...
> On 11/28/2011 2:19 PM, Roger Stafford wrote:
>> dpb <none@non.net> wrote in message <jb0o04$r2i$2@speranza.aioe.org>...
>>> So would
>>>
>>> A(I)=1;
>> - - - - - - - -
>> I get what Nasser gets, dpb. My system treats the I elements as linear
>> indices.
>
> Yeah, that's "my bad" on that-there one, sorry.
>
> It seems like it _should_ work...but doesn't. Don't know precisely why
> TMW chose the implementation as they did of A(I(:)) instead of the literal
> meaning of the index array elements.

I'm not certain either (you'd have to ask Cleve, probably) but I believe
it's because linear indexing is useful, and we didn't want A(I) to perform
linear indexing UNLESS the matrix I happened to have ndims(A) columns in
which case it would switch to subscripted indexing.

A = eye(4);
A(1:10) = 2; % linear indexing
A(1:3) = 3; % linear indexing
A(1:2) = 4; % If this just changed A(1, 2), wouldn't that be confusing and
break the nice "linear indexing" pattern?
A(1) = 5; % linear indexing

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Regarding Matrrix Indexing

From: Matt J

Date: 29 Nov, 2011 15:35:08

Message: 10 of 20

"Steven_Lord" <slord@mathworks.com> wrote in message <jb2sp1$26i$1@newscl01ah.mathworks.com>...
>
> > It seems like it _should_ work...but doesn't. Don't know precisely why
> > TMW chose the implementation as they did of A(I(:)) instead of the literal
> > meaning of the index array elements.
>
> I'm not certain either (you'd have to ask Cleve, probably) but I believe
> it's because linear indexing is useful, and we didn't want A(I) to perform
> linear indexing UNLESS the matrix I happened to have ndims(A) columns in
> which case it would switch to subscripted indexing.
================

The sense in that is pretty clear, although it also seems painful to have to go through SUB2IND all the time, especially since SUB2IND is implemented only in Mcode and is therefore slow. Seems like you could enable an indexing syntax like A({I}) to trigger non-tensorial subscript indexing. Yes, I know. Put in an enhancement request...

Subject: Regarding Matrrix Indexing

From: dpb

Date: 29 Nov, 2011 15:53:14

Message: 11 of 20

On 11/29/2011 9:12 AM, Steven_Lord wrote:
...

>> It seems like it _should_ work...but doesn't. Don't know precisely why
>> TMW chose the implementation as they did of A(I(:)) instead of the
>> literal meaning of the index array elements.
>
> I'm not certain either (you'd have to ask Cleve, probably) but I believe
> it's because linear indexing is useful, and we didn't want A(I) to
> perform linear indexing UNLESS the matrix I happened to have ndims(A)
> columns in which case it would switch to subscripted indexing.
>
> A = eye(4);
> A(1:10) = 2; % linear indexing
> A(1:3) = 3; % linear indexing
> A(1:2) = 4; % If this just changed A(1, 2), wouldn't that be confusing
> and break the nice "linear indexing" pattern?
> A(1) = 5; % linear indexing

I don't grok the

 > A(1:2) = 4; % If this just changed A(1, 2),

example comment, exactly. The list as written is explicit and 1D so it
would/could be interpreted as linear. If one wanted only A(1,2) then
one would write it that way.

I think users would have gotten to where it would have been expected
behavior if the other parsing had been selected. It would require
possibly explicit ':' in places it doesn't as is, I'm not sure; I
haven't tried to work on the actual parsing rules in detail.

I would guess the choice was strongly owing to the linear nature of
matrix storage in memory that was so common to manipulate manually in
the days when Cleve was starting to code Matlab. Then we all used to
handle "dynamic" memory by things such as large blank COMMON and pass a
singly-dimensioned (static) array address around and then use it however
the local routine needed before such wonders were handled for us. When
so used to the ind2sub<->sub2ind duality manually computed for such
"tricks" it would be natural to simply keep that approach.

Things were _much_ different way back when... :)

(BTW, as shows I'm sure often, being within hailing distance of a just a
handful of years of Cleve in longevity means saw/used/wrote a lot of
that kind of stuff in days past.)

--

Subject: Regarding Matrrix Indexing

From: Steven_Lord

Date: 29 Nov, 2011 18:07:50

Message: 12 of 20



"dpb" <none@non.net> wrote in message news:jb2v59$9r5$1@speranza.aioe.org...
> On 11/29/2011 9:12 AM, Steven_Lord wrote:
> ...
>
>>> It seems like it _should_ work...but doesn't. Don't know precisely why
>>> TMW chose the implementation as they did of A(I(:)) instead of the
>>> literal meaning of the index array elements.
>>
>> I'm not certain either (you'd have to ask Cleve, probably) but I believe
>> it's because linear indexing is useful, and we didn't want A(I) to
>> perform linear indexing UNLESS the matrix I happened to have ndims(A)
>> columns in which case it would switch to subscripted indexing.
>>
>> A = eye(4);
>> A(1:10) = 2; % linear indexing
>> A(1:3) = 3; % linear indexing
>> A(1:2) = 4; % If this just changed A(1, 2), wouldn't that be confusing
>> and break the nice "linear indexing" pattern?
>> A(1) = 5; % linear indexing
>
> I don't grok the
>
> > A(1:2) = 4; % If this just changed A(1, 2),
>
> example comment, exactly. The list as written is explicit and 1D

There's no such beastie in MATLAB. It is a vector, true, but (unless you
overload/shadow NDIMS) variables in MATLAB have at least two dimensions.

> so it would/could be interpreted as linear. If one wanted only A(1,2)
> then one would write it that way.

I was interpreting your comment "... A(I(:)) instead of the literal meaning
of the index array elements" to mean you were asking about whether it would
make sense for A([1 2; 3 4; 5 6]) to return [A(1, 2); A(3, 4); A(5, 6)] if A
were a 2-D array.
If that were the behavior, for a 2D matrix A then A(1:2) == A([1 2]) which
would return the scalar A(1, 2) while A(1:3) would be treated as [A(1),
A(2), A(3)].

Sorry if I misinterpreted what you were describing.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Regarding Matrrix Indexing

From: Parag Chandakkar

Date: 1 Dec, 2011 06:41:18

Message: 13 of 20

On Nov 29, 11:07 am, "Steven_Lord" <sl...@mathworks.com> wrote:
> "dpb" <n...@non.net> wrote in messagenews:jb2v59$9r5$1@speranza.aioe.org...
> > On 11/29/2011 9:12 AM, Steven_Lord wrote:
> > ...
>
> >>> It seems like it _should_ work...but doesn't. Don't know precisely why
> >>> TMW chose the implementation as they did of A(I(:)) instead of the
> >>> literal meaning of the index array elements.
>
> >> I'm not certain either (you'd have to ask Cleve, probably) but I believe
> >> it's because linear indexing is useful, and we didn't want A(I) to
> >> perform linear indexing UNLESS the matrix I happened to have ndims(A)
> >> columns in which case it would switch to subscripted indexing.
>
> >> A = eye(4);
> >> A(1:10) = 2; % linear indexing
> >> A(1:3) = 3; % linear indexing
> >> A(1:2) = 4; % If this just changed A(1, 2), wouldn't that be confusing
> >> and break the nice "linear indexing" pattern?
> >> A(1) = 5; % linear indexing
>
> > I don't grok the
>
> > > A(1:2) = 4; % If this just changed A(1, 2),
>
> > example comment, exactly.  The list as written is explicit and 1D
>
> There's no such beastie in MATLAB. It is a vector, true, but (unless you
> overload/shadow NDIMS) variables in MATLAB have at least two dimensions.
>
> > so it would/could be interpreted as linear.  If one wanted only A(1,2)
> > then one would write it that way.
>
> I was interpreting your comment "... A(I(:)) instead of the literal meaning
> of the index array elements" to mean you were asking about whether it would
> make sense for A([1 2; 3 4; 5 6]) to return [A(1, 2); A(3, 4); A(5, 6)] if A
> were a 2-D array.
> If that were the behavior, for a 2D matrix A then A(1:2) == A([1 2]) which
> would return the scalar A(1, 2) while A(1:3) would be treated as [A(1),
> A(2), A(3)].
>
> Sorry if I misinterpreted what you were describing.
>
> *snip*
>
> --
> Steve Lord
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link onhttp://www.mathworks.com

Hi to all,

Thanks for responding to my question in such a detail. I am sorry that
I didn't follow the post after I got the solution.
@dpb: whatever you suggested that was the first thing I tried because
thought it gave me a wrong solution, it seems most obvious.

Again thanks to all.
Indeed, I was also thinking on Matt J's lines that MATLAB should come
up with a functio which performs tasks like this directly because it
seems more intuitive to me.

- Parag Shridhar Chandakkar.

Subject: Regarding Matrrix Indexing

From: Parag Chandakkar

Date: 1 Dec, 2011 06:43:14

Message: 14 of 20

On Nov 30, 11:41 pm, Parag Chandakkar <pchan...@asu.edu> wrote:
> On Nov 29, 11:07 am, "Steven_Lord" <sl...@mathworks.com> wrote:
>
>
>
>
>
>
>
>
>
> > "dpb" <n...@non.net> wrote in messagenews:jb2v59$9r5$1@speranza.aioe.org...
> > > On 11/29/2011 9:12 AM, Steven_Lord wrote:
> > > ...
>
> > >>> It seems like it _should_ work...but doesn't. Don't know precisely why
> > >>> TMW chose the implementation as they did of A(I(:)) instead of the
> > >>> literal meaning of the index array elements.
>
> > >> I'm not certain either (you'd have to ask Cleve, probably) but I believe
> > >> it's because linear indexing is useful, and we didn't want A(I) to
> > >> perform linear indexing UNLESS the matrix I happened to have ndims(A)
> > >> columns in which case it would switch to subscripted indexing.
>
> > >> A = eye(4);
> > >> A(1:10) = 2; % linear indexing
> > >> A(1:3) = 3; % linear indexing
> > >> A(1:2) = 4; % If this just changed A(1, 2), wouldn't that be confusing
> > >> and break the nice "linear indexing" pattern?
> > >> A(1) = 5; % linear indexing
>
> > > I don't grok the
>
> > > > A(1:2) = 4; % If this just changed A(1, 2),
>
> > > example comment, exactly.  The list as written is explicit and 1D
>
> > There's no such beastie in MATLAB. It is a vector, true, but (unless you
> > overload/shadow NDIMS) variables in MATLAB have at least two dimensions.
>
> > > so it would/could be interpreted as linear.  If one wanted only A(1,2)
> > > then one would write it that way.
>
> > I was interpreting your comment "... A(I(:)) instead of the literal meaning
> > of the index array elements" to mean you were asking about whether it would
> > make sense for A([1 2; 3 4; 5 6]) to return [A(1, 2); A(3, 4); A(5, 6)] if A
> > were a 2-D array.
> > If that were the behavior, for a 2D matrix A then A(1:2) == A([1 2]) which
> > would return the scalar A(1, 2) while A(1:3) would be treated as [A(1),
> > A(2), A(3)].
>
> > Sorry if I misinterpreted what you were describing.
>
> > *snip*
>
> > --
> > Steve Lord
> > sl...@mathworks.com
> > To contact Technical Support use the Contact Us link onhttp://www.mathworks.com
>
> Hi to all,
>
> Thanks for responding to my question in such a detail. I am sorry that
> I didn't follow the post after I got the solution.
> @dpb: whatever you suggested that was the first thing I tried because
> thought it gave me a wrong solution, it seems most obvious.
>
> Again thanks to all.
> Indeed, I was also thinking on Matt J's lines that MATLAB should come
> up with a functio which performs tasks like this directly because it
> seems more intuitive to me.
>
> -ParagShridharChandakkar.

But finally, I would like to tell you that I didn't use Sub2Ind
because that was not providing me the optimized solution. I used
Vectorization to get to the answer.
- Parag S Chandakkar

Subject: Regarding Matrrix Indexing

From: dpb

Date: 1 Dec, 2011 14:25:13

Message: 15 of 20

On 12/1/2011 12:43 AM, Parag Chandakkar wrote:
...

> But finally, I would like to tell you that I didn't use Sub2Ind
> because that was not providing me the optimized solution. I used
> Vectorization to get to the answer.

How, specifically???

--

Subject: Regarding Matrrix Indexing

From: Roger Stafford

Date: 1 Dec, 2011 16:20:09

Message: 16 of 20

Parag Chandakkar <pchandak@asu.edu> wrote in message <ad064238-3b02-44af-be52-0fabb8b37cce@s4g2000yqk.googlegroups.com>...
> But finally, I would like to tell you that I didn't use Sub2Ind
> because that was not providing me the optimized solution. I used
> Vectorization to get to the answer.
> - Parag S Chandakkar
- - - - - - - - -
  Did you do this:

 A(I(:,1)+size(A,1)*(I(:,2)-1)) = 1;

If so, that is precisely what 'sub2ind' does.

Roger Stafford

Subject: Regarding Matrrix Indexing

From: Matt J

Date: 1 Dec, 2011 16:37:08

Message: 17 of 20

"Roger Stafford" wrote in message <jb89fp$aqp$1@newscl01ah.mathworks.com>...
>
> Did you do this:
>
> A(I(:,1)+size(A,1)*(I(:,2)-1)) = 1;
>
> If so, that is precisely what 'sub2ind' does.
=================

Yes, but slower, because of all the input processing it has to do (in Mcode).

Subject: Regarding Matrrix Indexing

From: Parag S. Chandakkar

Date: 1 Dec, 2011 18:42:18

Message: 18 of 20

On Dec 1, 9:20 am, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> ParagChandakkar<pchan...@asu.edu> wrote in message <ad064238-3b02-44af-be52-0fabb8b37...@s4g2000yqk.googlegroups.com>...
> > But finally, I would like to tell you that I didn't use Sub2Ind
> > because that was not providing me the optimized solution. I used
> > Vectorization to get to the answer.
> > -ParagSChandakkar
>
> - - - - - - - - -
>   Did you do this:
>
>  A(I(:,1)+size(A,1)*(I(:,2)-1)) = 1;
>
> If so, that is precisely what 'sub2ind' does.
>
> Roger Stafford

No, I didn't try...
Thanks for telling.
- Parag S Chandakkar.

Subject: Regarding Matrrix Indexing

From: Parag S. Chandakkar

Date: 1 Dec, 2011 18:41:41

Message: 19 of 20

On Dec 1, 7:25 am, dpb <n...@non.net> wrote:
> On 12/1/2011 12:43 AM,ParagChandakkarwrote:
> ...
>
> > But finally, I would like to tell you that I didn't use Sub2Ind
> > because that was not providing me the optimized solution. I used
> > Vectorization to get to the answer.
>
> How, specifically???
>
> --

Basically, what I wanted to do was get the locations by sub2Ind at
runtime and then assign a particular number only to those locations.
But I was using "find" function and then sub2Ind which was making my
program slower... So I converted everything into a vector and then by
logical indexing I could get those locations, assign a particular
number and do this for the entire matrix... then use reshape to get
back the matrix...
Worked much faster for me... from 20 sec to 3 sec...

Thanks.
- Parag S Chandakkar.

Subject: Regarding Matrrix Indexing

From: dpb

Date: 1 Dec, 2011 19:43:51

Message: 20 of 20

On 12/1/2011 12:41 PM, Parag S. Chandakkar wrote:
> On Dec 1, 7:25 am, dpb<n...@non.net> wrote:
>> On 12/1/2011 12:43 AM,ParagChandakkarwrote:
>> ...
>>
>>> ... I used Vectorization to get to the answer.
>>
>> How, specifically???
>>
...
> ... So I converted everything into a vector and then by
> logical indexing I could get those locations, assign a particular
> number and do this for the entire matrix... then use reshape to get
> back the matrix...
...

Ok, I grok that.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us