Got Questions? Get Answers.
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:
How do you do this fast?

Subject: How do you do this fast?

From: Luna Moon

Date: 11 Jun, 2010 20:26:13

Message: 1 of 9

Hi all,

I have sets A, B, C, where C is the biggest set, A is the smallest,

C>B>A, i.e. C contains B contains A.

These are indices indeed.

I have a matrix m x n matrix MatrixC, where C=[1:n].

I have created a matrix MatrixB, which is

MatrixB=MatrixC(:, B).

Now I want to obtain MatrixA, which is

MatrixA=MatrixC(:, A).

---------------------------

However, in reality, actually for cost reasons, I didn't measure all
MatrixC,

instead, I took measurements for MatrixB.

So all I have now is MatrixB, and sets A, B, C.

i.e. the indices A and B are "in C's language".

i.e. the indices A and B are numbered according to their positions in
C=[1:n].

So the question is:

how do I obtain MatrixA from MatrixB and sets A, B, C?

I currently use a "for" loop plus "find" etc. to do this job,

are there any fast approach without using "for" and "find"?

Mine is too slow... too stupid...

Thank you!

Subject: How do you do this fast?

From: EE Student

Date: 11 Jun, 2010 22:19:04

Message: 2 of 9

Luna Moon <lunamoonmoon@gmail.com> wrote in message <33a67c34-769a-44db-95c4-1ff9f71dccd9@a42g2000vbl.googlegroups.com>...
> Hi all,
>
> I have sets A, B, C, where C is the biggest set, A is the smallest,
>
> C>B>A, i.e. C contains B contains A.
>
> These are indices indeed.
>
> I have a matrix m x n matrix MatrixC, where C=[1:n].
>
> I have created a matrix MatrixB, which is
>
> MatrixB=MatrixC(:, B).
>
> Now I want to obtain MatrixA, which is
>
> MatrixA=MatrixC(:, A).
>
> ---------------------------
>
> However, in reality, actually for cost reasons, I didn't measure all
> MatrixC,
>
> instead, I took measurements for MatrixB.
>
> So all I have now is MatrixB, and sets A, B, C.
>
> i.e. the indices A and B are "in C's language".
>
> i.e. the indices A and B are numbered according to their positions in
> C=[1:n].
>
> So the question is:
>
> how do I obtain MatrixA from MatrixB and sets A, B, C?
>
> I currently use a "for" loop plus "find" etc. to do this job,
>
> are there any fast approach without using "for" and "find"?
>
> Mine is too slow... too stupid...
>
> Thank you!


Luna,

I dont quite understand what you are trying to do, but what I gather is that you are trying to find the portion A in B and B in C right? Do you already know the contents of A, B, and C and you just need to find where they are relative to each other? If so, there may be a better way but I would do this as a template matching problem. Use normxcorr2 with A as the template for B, and B as the template for C. Or at least read the help file and examples on normxcorr2 and template matching and see if this is along the lines of what you are attempting to do, otherwise you may want to try and explain better and post the code you have written so far because its tough to follow what your goal is.

Nick

Subject: How do you do this fast?

From: Patrick

Date: 11 Jun, 2010 22:20:08

Message: 3 of 9

Hmm, your post is a bit confusing. Could you give a small example?

Luna Moon <lunamoonmoon@gmail.com> wrote in message <33a67c34-769a-
44db-95c4-1ff9f71dccd9@a42g2000vbl.googlegroups.com>...

> Hi all,
>
> I have sets A, B, C, where C is the biggest set, A is the smallest,
>
> C>B>A, i.e. C contains B contains A.
>
> These are indices indeed.
>
> I have a matrix m x n matrix MatrixC, where C=[1:n].
>
> I have created a matrix MatrixB, which is
>
> MatrixB=MatrixC(:, B).
>
> Now I want to obtain MatrixA, which is
>
> MatrixA=MatrixC(:, A).
>
> ---------------------------
>
> However, in reality, actually for cost reasons, I didn't measure all
> MatrixC,
>
> instead, I took measurements for MatrixB.
>
> So all I have now is MatrixB, and sets A, B, C.
>
> i.e. the indices A and B are "in C's language".
>
> i.e. the indices A and B are numbered according to their positions in
> C=[1:n].
>
> So the question is:
>
> how do I obtain MatrixA from MatrixB and sets A, B, C?
>
> I currently use a "for" loop plus "find" etc. to do this job,
>
> are there any fast approach without using "for" and "find"?
>
> Mine is too slow... too stupid...
>
> Thank you!

Subject: How do you do this fast?

From: Luna Moon

Date: 12 Jun, 2010 00:48:49

Message: 4 of 9

On Jun 11, 6:19 pm, "EE Student " <n...@cec.wustl.edu> wrote:
> Luna Moon <lunamoonm...@gmail.com> wrote in message <33a67c34-769a-44db-95c4-1ff9f71dc...@a42g2000vbl.googlegroups.com>...
> > Hi all,
>
> > I have sets A, B, C, where C is the biggest set, A is the smallest,
>
> > C>B>A, i.e. C contains B contains A.
>
> > These are indices indeed.
>
> > I have a matrix m x n matrix MatrixC, where C=[1:n].
>
> > I have created a matrix MatrixB, which is
>
> > MatrixB=MatrixC(:, B).
>
> > Now I want to obtain MatrixA, which is
>
> > MatrixA=MatrixC(:, A).
>
> > ---------------------------
>
> > However, in reality, actually for cost reasons, I didn't measure all
> > MatrixC,
>
> > instead, I took measurements for MatrixB.
>
> > So all I have now is MatrixB, and sets A, B, C.
>
> > i.e. the indices A and B are "in C's language".
>
> > i.e. the indices A and B are numbered according to their positions in
> > C=[1:n].
>
> > So the question is:
>
> > how do I obtain MatrixA from MatrixB and sets A, B, C?
>
> > I currently use a "for" loop plus "find" etc. to do this job,
>
> > are there any fast approach without using "for" and "find"?
>
> > Mine is too slow... too stupid...
>
> > Thank you!
>
> Luna,
>
> I dont quite understand what you are trying to do, but what I gather is that you are trying to find the portion A in B and B in C right?  Do you already know the contents of A, B, and C and you just need to find where they are relative to each other?  If so, there may be a better way but I would do this as a template matching problem.  Use normxcorr2 with A as the template for B, and B as the template for C.  Or at least read the help file and examples on normxcorr2 and template matching and see if this is along the lines of what you are attempting to do, otherwise you may want to try and explain better and post the code you have written so far because its tough to follow what your goal is.
>
> Nick

Thanks Nick. Sorry for not being clear.

Here is an example:

Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].

B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all
referenced w.r.t. C.

So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,
9:36] columns from the original data matrix C.

However, due to costs of measurements, I don't have MatrixC, I have
only measured MatrixB.

I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the
numbers of which are again referenced w.r.t C.

And A is B's subset.

I would like to obtain

MatrixA=MatrixC(:, A) ideally speaking.

However I don't have MtrixC, I only have MatrixB.

So how do I obtain MatrixA from MatrixB and the index sets A, B, C
without "for" loops?

Thank you

Subject: How do you do this fast?

From: Luna Moon

Date: 12 Jun, 2010 00:49:05

Message: 5 of 9

On Jun 11, 6:20 pm, "Patrick " <praph...@gmail.com> wrote:
> Hmm, your post is a bit confusing.  Could you give a small example?
>
> Luna Moon <lunamoonm...@gmail.com> wrote in message <33a67c34-769a-
>
> 44db-95c4-1ff9f71dc...@a42g2000vbl.googlegroups.com>...
>
> > Hi all,
>
> > I have sets A, B, C, where C is the biggest set, A is the smallest,
>
> > C>B>A, i.e. C contains B contains A.
>
> > These are indices indeed.
>
> > I have a matrix m x n matrix MatrixC, where C=[1:n].
>
> > I have created a matrix MatrixB, which is
>
> > MatrixB=MatrixC(:, B).
>
> > Now I want to obtain MatrixA, which is
>
> > MatrixA=MatrixC(:, A).
>
> > ---------------------------
>
> > However, in reality, actually for cost reasons, I didn't measure all
> > MatrixC,
>
> > instead, I took measurements for MatrixB.
>
> > So all I have now is MatrixB, and sets A, B, C.
>
> > i.e. the indices A and B are "in C's language".
>
> > i.e. the indices A and B are numbered according to their positions in
> > C=[1:n].
>
> > So the question is:
>
> > how do I obtain MatrixA from MatrixB and sets A, B, C?
>
> > I currently use a "for" loop plus "find" etc. to do this job,
>
> > are there any fast approach without using "for" and "find"?
>
> > Mine is too slow... too stupid...
>
> > Thank you!

Thanks Patrick. Sorry for not being clear.

Here is an example:

Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].

B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all
referenced w.r.t. C.

So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,
9:36] columns from the original data matrix C.

However, due to costs of measurements, I don't have MatrixC, I have
only measured MatrixB.

I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the
numbers of which are again referenced w.r.t C.

And A is B's subset.

I would like to obtain

MatrixA=MatrixC(:, A) ideally speaking.

However I don't have MtrixC, I only have MatrixB.

So how do I obtain MatrixA from MatrixB and the index sets A, B, C
without "for" loops?

Thank you

Subject: How do you do this fast?

From: ImageAnalyst

Date: 12 Jun, 2010 02:12:44

Message: 6 of 9

Still clear as mud. So MatrixC is a 1000 x 36 2-dimensional array (of
36,000 elements total), and C=[1:36] is a one dimensional array that
looks like [1,2,3,4,5,......34,35,36]. Then we have "MtrixC" which I
guess is that same as MatrixC (just a typo). Plus we have MatrixA,
MatrixB, A, and finally B.

But MatrixB is certain columns from C, so MatrixB must also be a 2D
array. But C is only a 1-D array (row vector) so it's columns are
only element high, so I guess that means MatrixB is actually also a 1D
row vector.

I gave up at this point.

Subject: How do you do this fast?

From: Roger Stafford

Date: 12 Jun, 2010 02:36:03

Message: 7 of 9

Luna Moon <lunamoonmoon@gmail.com> wrote in message <8bd25c7a-3b59-4b8f-b6a1-8eb1ebbec132@a1g2000vbl.googlegroups.com>...
> ........
> Here is an example:
> Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].
> B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all
> referenced w.r.t. C.
> So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,
> 9:36] columns from the original data matrix C.
> However, due to costs of measurements, I don't have MatrixC, I have
> only measured MatrixB.
> I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the
> numbers of which are again referenced w.r.t C.
> And A is B's subset.
> I would like to obtain
> MatrixA=MatrixC(:, A) ideally speaking.
> However I don't have MtrixC, I only have MatrixB.
> So how do I obtain MatrixA from MatrixB and the index sets A, B, C
> without "for" loops?
> .......
- - - - - - -
  Does this do what you want? I too had trouble understanding your question.

 [ignore,p] = ismember(A,B);
 matrixA = matrixB(:,B(p));

Roger Stafford

Subject: How do you do this fast?

From: Steven Lord

Date: 14 Jun, 2010 15:36:12

Message: 8 of 9


"Luna Moon" <lunamoonmoon@gmail.com> wrote in message
news:8bd25c7a-3b59-4b8f-b6a1-8eb1ebbec132@a1g2000vbl.googlegroups.com...
On Jun 11, 6:20 pm, "Patrick " <praph...@gmail.com> wrote:
> Hmm, your post is a bit confusing. Could you give a small example?

The example you posted is still too large and general to understand, I
think. Let's try this. Run the next four lines of code to generate four
variables (saving any existing variables with those names first, if you
don't want them to be overwritten)

C = 1:4;
MatrixC = reshape(1:20, 5 4);
B = [2 5 3];
MatrixB = MatrixC(:, B);

Now show us how to generate a SMALL sample A and a small sample MatrixA and
use those six variables to explain EXACTLY what you want to receive in the
end and how you want to compute it. If one of the sample variables I've
given does not satisfy the requirements of your problem, explain why not and
show us how to explicitly create a sample variable that does.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: How do you do this fast?

From: Roger Stafford

Date: 14 Jun, 2010 20:02:05

Message: 9 of 9

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <huurqj$jtj$1@fred.mathworks.com>...
> Does this do what you want? I too had trouble understanding your question.
>
> [ignore,p] = ismember(A,B);
> matrixA = matrixB(:,B(p));
>
> Roger Stafford
- - - - - -
  I made a mistake on that code I sent. It should have read:

 [ignore,p] = ismember(A,B);
 matrixA = matrixB(:,p);

Roger Stafford

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