http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454
MATLAB Central Newsreader  How do you do this fast?
Feed for thread: How do you do this fast?
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 11 Jun 2010 20:26:13 +0000
How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753772
Luna Moon
Hi all,<br>
<br>
I have sets A, B, C, where C is the biggest set, A is the smallest,<br>
<br>
C>B>A, i.e. C contains B contains A.<br>
<br>
These are indices indeed.<br>
<br>
I have a matrix m x n matrix MatrixC, where C=[1:n].<br>
<br>
I have created a matrix MatrixB, which is<br>
<br>
MatrixB=MatrixC(:, B).<br>
<br>
Now I want to obtain MatrixA, which is<br>
<br>
MatrixA=MatrixC(:, A).<br>
<br>
<br>
<br>
However, in reality, actually for cost reasons, I didn't measure all<br>
MatrixC,<br>
<br>
instead, I took measurements for MatrixB.<br>
<br>
So all I have now is MatrixB, and sets A, B, C.<br>
<br>
i.e. the indices A and B are "in C's language".<br>
<br>
i.e. the indices A and B are numbered according to their positions in<br>
C=[1:n].<br>
<br>
So the question is:<br>
<br>
how do I obtain MatrixA from MatrixB and sets A, B, C?<br>
<br>
I currently use a "for" loop plus "find" etc. to do this job,<br>
<br>
are there any fast approach without using "for" and "find"?<br>
<br>
Mine is too slow... too stupid...<br>
<br>
Thank you!

Fri, 11 Jun 2010 22:19:04 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753812
EE Student
Luna Moon <lunamoonmoon@gmail.com> wrote in message <33a67c34769a44db95c41ff9f71dccd9@a42g2000vbl.googlegroups.com>...<br>
> Hi all,<br>
> <br>
> I have sets A, B, C, where C is the biggest set, A is the smallest,<br>
> <br>
> C>B>A, i.e. C contains B contains A.<br>
> <br>
> These are indices indeed.<br>
> <br>
> I have a matrix m x n matrix MatrixC, where C=[1:n].<br>
> <br>
> I have created a matrix MatrixB, which is<br>
> <br>
> MatrixB=MatrixC(:, B).<br>
> <br>
> Now I want to obtain MatrixA, which is<br>
> <br>
> MatrixA=MatrixC(:, A).<br>
> <br>
> <br>
> <br>
> However, in reality, actually for cost reasons, I didn't measure all<br>
> MatrixC,<br>
> <br>
> instead, I took measurements for MatrixB.<br>
> <br>
> So all I have now is MatrixB, and sets A, B, C.<br>
> <br>
> i.e. the indices A and B are "in C's language".<br>
> <br>
> i.e. the indices A and B are numbered according to their positions in<br>
> C=[1:n].<br>
> <br>
> So the question is:<br>
> <br>
> how do I obtain MatrixA from MatrixB and sets A, B, C?<br>
> <br>
> I currently use a "for" loop plus "find" etc. to do this job,<br>
> <br>
> are there any fast approach without using "for" and "find"?<br>
> <br>
> Mine is too slow... too stupid...<br>
> <br>
> Thank you!<br>
<br>
<br>
Luna, <br>
<br>
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.<br>
<br>
Nick

Fri, 11 Jun 2010 22:20:08 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753814
Patrick
Hmm, your post is a bit confusing. Could you give a small example?<br>
<br>
Luna Moon <lunamoonmoon@gmail.com> wrote in message <33a67c34769a<br>
44db95c41ff9f71dccd9@a42g2000vbl.googlegroups.com>...<br>
<br>
> Hi all,<br>
> <br>
> I have sets A, B, C, where C is the biggest set, A is the smallest,<br>
> <br>
> C>B>A, i.e. C contains B contains A.<br>
> <br>
> These are indices indeed.<br>
> <br>
> I have a matrix m x n matrix MatrixC, where C=[1:n].<br>
> <br>
> I have created a matrix MatrixB, which is<br>
> <br>
> MatrixB=MatrixC(:, B).<br>
> <br>
> Now I want to obtain MatrixA, which is<br>
> <br>
> MatrixA=MatrixC(:, A).<br>
> <br>
> <br>
> <br>
> However, in reality, actually for cost reasons, I didn't measure all<br>
> MatrixC,<br>
> <br>
> instead, I took measurements for MatrixB.<br>
> <br>
> So all I have now is MatrixB, and sets A, B, C.<br>
> <br>
> i.e. the indices A and B are "in C's language".<br>
> <br>
> i.e. the indices A and B are numbered according to their positions in<br>
> C=[1:n].<br>
> <br>
> So the question is:<br>
> <br>
> how do I obtain MatrixA from MatrixB and sets A, B, C?<br>
> <br>
> I currently use a "for" loop plus "find" etc. to do this job,<br>
> <br>
> are there any fast approach without using "for" and "find"?<br>
> <br>
> Mine is too slow... too stupid...<br>
> <br>
> Thank you!

Sat, 12 Jun 2010 00:48:49 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753840
Luna Moon
On Jun 11, 6:19 pm, "EE Student " <n...@cec.wustl.edu> wrote:<br>
> Luna Moon <lunamoonm...@gmail.com> wrote in message <33a67c34769a44db95c41ff9f71dc...@a42g2000vbl.googlegroups.com>...<br>
> > Hi all,<br>
><br>
> > I have sets A, B, C, where C is the biggest set, A is the smallest,<br>
><br>
> > C>B>A, i.e. C contains B contains A.<br>
><br>
> > These are indices indeed.<br>
><br>
> > I have a matrix m x n matrix MatrixC, where C=[1:n].<br>
><br>
> > I have created a matrix MatrixB, which is<br>
><br>
> > MatrixB=MatrixC(:, B).<br>
><br>
> > Now I want to obtain MatrixA, which is<br>
><br>
> > MatrixA=MatrixC(:, A).<br>
><br>
> > <br>
><br>
> > However, in reality, actually for cost reasons, I didn't measure all<br>
> > MatrixC,<br>
><br>
> > instead, I took measurements for MatrixB.<br>
><br>
> > So all I have now is MatrixB, and sets A, B, C.<br>
><br>
> > i.e. the indices A and B are "in C's language".<br>
><br>
> > i.e. the indices A and B are numbered according to their positions in<br>
> > C=[1:n].<br>
><br>
> > So the question is:<br>
><br>
> > how do I obtain MatrixA from MatrixB and sets A, B, C?<br>
><br>
> > I currently use a "for" loop plus "find" etc. to do this job,<br>
><br>
> > are there any fast approach without using "for" and "find"?<br>
><br>
> > Mine is too slow... too stupid...<br>
><br>
> > Thank you!<br>
><br>
> Luna,<br>
><br>
> 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.<br>
><br>
> Nick<br>
<br>
Thanks Nick. Sorry for not being clear.<br>
<br>
Here is an example:<br>
<br>
Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].<br>
<br>
B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all<br>
referenced w.r.t. C.<br>
<br>
So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,<br>
9:36] columns from the original data matrix C.<br>
<br>
However, due to costs of measurements, I don't have MatrixC, I have<br>
only measured MatrixB.<br>
<br>
I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the<br>
numbers of which are again referenced w.r.t C.<br>
<br>
And A is B's subset.<br>
<br>
I would like to obtain<br>
<br>
MatrixA=MatrixC(:, A) ideally speaking.<br>
<br>
However I don't have MtrixC, I only have MatrixB.<br>
<br>
So how do I obtain MatrixA from MatrixB and the index sets A, B, C<br>
without "for" loops?<br>
<br>
Thank you

Sat, 12 Jun 2010 00:49:05 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753841
Luna Moon
On Jun 11, 6:20 pm, "Patrick " <praph...@gmail.com> wrote:<br>
> Hmm, your post is a bit confusing. Could you give a small example?<br>
><br>
> Luna Moon <lunamoonm...@gmail.com> wrote in message <33a67c34769a<br>
><br>
> 44db95c41ff9f71dc...@a42g2000vbl.googlegroups.com>...<br>
><br>
> > Hi all,<br>
><br>
> > I have sets A, B, C, where C is the biggest set, A is the smallest,<br>
><br>
> > C>B>A, i.e. C contains B contains A.<br>
><br>
> > These are indices indeed.<br>
><br>
> > I have a matrix m x n matrix MatrixC, where C=[1:n].<br>
><br>
> > I have created a matrix MatrixB, which is<br>
><br>
> > MatrixB=MatrixC(:, B).<br>
><br>
> > Now I want to obtain MatrixA, which is<br>
><br>
> > MatrixA=MatrixC(:, A).<br>
><br>
> > <br>
><br>
> > However, in reality, actually for cost reasons, I didn't measure all<br>
> > MatrixC,<br>
><br>
> > instead, I took measurements for MatrixB.<br>
><br>
> > So all I have now is MatrixB, and sets A, B, C.<br>
><br>
> > i.e. the indices A and B are "in C's language".<br>
><br>
> > i.e. the indices A and B are numbered according to their positions in<br>
> > C=[1:n].<br>
><br>
> > So the question is:<br>
><br>
> > how do I obtain MatrixA from MatrixB and sets A, B, C?<br>
><br>
> > I currently use a "for" loop plus "find" etc. to do this job,<br>
><br>
> > are there any fast approach without using "for" and "find"?<br>
><br>
> > Mine is too slow... too stupid...<br>
><br>
> > Thank you!<br>
<br>
Thanks Patrick. Sorry for not being clear.<br>
<br>
Here is an example:<br>
<br>
Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].<br>
<br>
B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all<br>
referenced w.r.t. C.<br>
<br>
So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,<br>
9:36] columns from the original data matrix C.<br>
<br>
However, due to costs of measurements, I don't have MatrixC, I have<br>
only measured MatrixB.<br>
<br>
I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the<br>
numbers of which are again referenced w.r.t C.<br>
<br>
And A is B's subset.<br>
<br>
I would like to obtain<br>
<br>
MatrixA=MatrixC(:, A) ideally speaking.<br>
<br>
However I don't have MtrixC, I only have MatrixB.<br>
<br>
So how do I obtain MatrixA from MatrixB and the index sets A, B, C<br>
without "for" loops?<br>
<br>
Thank you

Sat, 12 Jun 2010 02:12:44 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753851
ImageAnalyst
Still clear as mud. So MatrixC is a 1000 x 36 2dimensional array (of<br>
36,000 elements total), and C=[1:36] is a one dimensional array that<br>
looks like [1,2,3,4,5,......34,35,36]. Then we have "MtrixC" which I<br>
guess is that same as MatrixC (just a typo). Plus we have MatrixA,<br>
MatrixB, A, and finally B.<br>
<br>
But MatrixB is certain columns from C, so MatrixB must also be a 2D<br>
array. But C is only a 1D array (row vector) so it's columns are<br>
only element high, so I guess that means MatrixB is actually also a 1D<br>
row vector.<br>
<br>
I gave up at this point.

Sat, 12 Jun 2010 02:36:03 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#753857
Roger Stafford
Luna Moon <lunamoonmoon@gmail.com> wrote in message <8bd25c7a3b594b8fb6a18eb1ebbec132@a1g2000vbl.googlegroups.com>...<br>
> ........<br>
> Here is an example:<br>
> Originally the data matrix MatrixC is 1000 x 36, so C=[1:36].<br>
> B=[1, 3, 5, 7, 9:36]; so there are 32 numbers in B, they are all<br>
> referenced w.r.t. C.<br>
> So I have the data matrix MatrixB, consisting of the [1, 3, 5, 7,<br>
> 9:36] columns from the original data matrix C.<br>
> However, due to costs of measurements, I don't have MatrixC, I have<br>
> only measured MatrixB.<br>
> I also have A=[1, 5, 9, 11, 13, 25, 31, 33, 34, 35, 36], all the<br>
> numbers of which are again referenced w.r.t C.<br>
> And A is B's subset.<br>
> I would like to obtain<br>
> MatrixA=MatrixC(:, A) ideally speaking.<br>
> However I don't have MtrixC, I only have MatrixB.<br>
> So how do I obtain MatrixA from MatrixB and the index sets A, B, C<br>
> without "for" loops?<br>
> .......<br>
      <br>
Does this do what you want? I too had trouble understanding your question.<br>
<br>
[ignore,p] = ismember(A,B);<br>
matrixA = matrixB(:,B(p));<br>
<br>
Roger Stafford

Mon, 14 Jun 2010 15:36:12 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#754283
Steven Lord
<br>
"Luna Moon" <lunamoonmoon@gmail.com> wrote in message <br>
news:8bd25c7a3b594b8fb6a18eb1ebbec132@a1g2000vbl.googlegroups.com...<br>
On Jun 11, 6:20 pm, "Patrick " <praph...@gmail.com> wrote:<br>
> Hmm, your post is a bit confusing. Could you give a small example?<br>
<br>
The example you posted is still too large and general to understand, I <br>
think. Let's try this. Run the next four lines of code to generate four <br>
variables (saving any existing variables with those names first, if you <br>
don't want them to be overwritten)<br>
<br>
C = 1:4;<br>
MatrixC = reshape(1:20, 5 4);<br>
B = [2 5 3];<br>
MatrixB = MatrixC(:, B);<br>
<br>
Now show us how to generate a SMALL sample A and a small sample MatrixA and <br>
use those six variables to explain EXACTLY what you want to receive in the <br>
end and how you want to compute it. If one of the sample variables I've <br>
given does not satisfy the requirements of your problem, explain why not and <br>
show us how to explicitly create a sample variable that does.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a><br>
To contact Technical Support use the Contact Us link on <br>
<a href="http://www.mathworks.com">http://www.mathworks.com</a>

Mon, 14 Jun 2010 20:02:05 +0000
Re: How do you do this fast?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284454#754367
Roger Stafford
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <huurqj$jtj$1@fred.mathworks.com>...<br>
> Does this do what you want? I too had trouble understanding your question.<br>
> <br>
> [ignore,p] = ismember(A,B);<br>
> matrixA = matrixB(:,B(p));<br>
> <br>
> Roger Stafford<br>
     <br>
I made a mistake on that code I sent. It should have read:<br>
<br>
[ignore,p] = ismember(A,B);<br>
matrixA = matrixB(:,p);<br>
<br>
Roger Stafford