http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414
MATLAB Central Newsreader  MTIMESX when Inner matrix dimensions are not agree.
Feed for thread: MTIMESX when Inner matrix dimensions are not agree.
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

Wed, 17 Apr 2013 22:10:10 +0000
MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902639
ghasem
Hi.<br>
I want to use from MTIMEXS method ( by James Tursa) to multiply 3d arrays,when Inner matrix dimensions are not agree.<br>
for example I have:<br>
A=rand(33,32,32);<br>
B=rand(33,32,32);<br>
So,if I use from " mtimesx(A,B) , I will get this error:<br>
??? Error using ==> mtimesx<br>
Inner matrix dimensions must agree.<br>
<br>
while,I used from Point by point multiplication method,previously.i.e:<br>
C = A.*B<br>
============<br>
can I use from "mtimesx" or "mmx" methods in this case?<br>
best wishes...<br>
ghasem

Thu, 18 Apr 2013 06:07:10 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902653
ghasem
there is not any idea?

Thu, 18 Apr 2013 06:50:09 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902658
Bruno Luong
"ghasem " <shaban_sadeghi@yahoo.com> wrote in message <kko2ie$bm2$1@newscl01ah.mathworks.com>...<br>
> there is not any idea?<br>
<br>
mtimesx performs matrix multiplication, not pointwise.<br>
<br>
Bruno

Thu, 18 Apr 2013 07:50:10 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902660
ghasem
> mtimesx performs matrix multiplication, not pointwise.<br>
> <br>
> Bruno<br>
==============<br>
yes,I know.But I want to know that is there any fast method for element by element multiplication of two 3d arrays?<br>
ghasem

Thu, 18 Apr 2013 08:10:52 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902663
Nasser M. Abbasi
On 4/18/2013 2:50 AM, ghasem wrote:<br>
>> mtimesx performs matrix multiplication, not pointwise.<br>
>><br>
>> Bruno<br>
> ==============<br>
<br>
<br>
> yes,I know.But I want to know that is there any fast method for element by element<br>
>multiplication of two 3d arrays?<br>
> ghasem<br>
><br>
<br>
What is wrong with just using .* ?<br>
<br>
EDU>> help .*<br>
<br>
" .* Array multiply.<br>
X.*Y denotes elementbyelement multiplication.<br>
X and Y must have the same dimensions"<br>
<br>
<br>
EDU>> A=rand(2,2,2);<br>
EDU>> B=rand(2,2,2);<br>
EDU>> A.*B<br>
<br>
Nasser

Thu, 18 Apr 2013 08:46:09 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902665
ghasem
> EDU>> help .*<br>
> <br>
> " .* Array multiply.<br>
> X.*Y denotes elementbyelement multiplication.<br>
> X and Y must have the same dimensions"<br>
> <br>
> <br>
> EDU>> A=rand(2,2,2);<br>
> EDU>> B=rand(2,2,2);<br>
> EDU>> A.*B<br>
> <br>
> Nasser<br>
> <br>
>=================================<br>
I'm familiar with .* operator.<br>
I want to know that this method is best and fastest?<br>
also,I have one question:<br>
how can I use from singlethreade BLAS for mmx in matlab?<br>
i.e,how link singlethreaded BLAS to matlab to use from it in mmx?

Thu, 18 Apr 2013 10:22:09 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902672
Bruno Luong
"ghasem " <shaban_sadeghi@yahoo.com> wrote in message <kko8ji$qlk$1@newscl01ah.mathworks.com>...<br>
> > mtimesx performs matrix multiplication, not pointwise.<br>
> > <br>
> > Bruno<br>
> ==============<br>
> yes,I know.<br>
<br>
No you didn't, since you ask about "matrix dimension must agree" error.<br>
<br>
And you start over again with mmx.<br>
<br>
Bruno

Thu, 18 Apr 2013 12:28:09 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902677
ghasem
> No you didn't, since you ask about "matrix dimension must agree" error.<br>
> <br>
> And you start over again with mmx.<br>
> <br>
> Bruno<br>
=================================<br>
yes,I know,but you don't understand my question.<br>
in fact,my question was as follow:<br>
if I want to use from MTIMESX for fast opertaion,but second dimension of A is not equal with first diemnsion of B,but second and third dimensions in both A and B are same,is a good choice MTIMESX?<br>
for example:<br>
a=rand(33,32,32);<br>
b=rand(33,32,32);<br>
I konw that : c = mtimesx(a,b) => is false!<br>
also,I know that simply : c =a.*b<br>
but I want to use from:<br>
c = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2]);<br>
NOW,my question was:<br>
between " .* " operator and " mtimesx (or mmx)" , which is faster?<br>
ghasem

Thu, 18 Apr 2013 13:57:02 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902681
Steven_Lord
<br>
<br>
"ghasem " <shaban_sadeghi@yahoo.com> wrote in message <br>
news:kkoosp$a0m$1@newscl01ah.mathworks.com...<br>
>> No you didn't, since you ask about "matrix dimension must agree" error.<br>
>><br>
>> And you start over again with mmx.<br>
>><br>
>> Bruno<br>
> =================================<br>
> yes,I know,but you don't understand my question.<br>
> in fact,my question was as follow:<br>
> if I want to use from MTIMESX for fast opertaion,but second dimension of A <br>
> is not equal with first diemnsion of B,but second and third dimensions in <br>
> both A and B are same,is a good choice MTIMESX?<br>
> for example:<br>
> a=rand(33,32,32);<br>
> b=rand(33,32,32);<br>
> I konw that : c = mtimesx(a,b) => is false!<br>
> also,I know that simply : c =a.*b<br>
> but I want to use from:<br>
> c = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2]);<br>
<br>
Why??? Why do this when TIMES does the same operation without performing <br>
three permutations (each of which shuffles memory around and so INCREASES <br>
the time required for the operation?)<br>
<br>
> NOW,my question was:<br>
> between " .* " operator and " mtimesx (or mmx)" , which is faster?<br>
<br>
I have not used MTIMESX but I would expect "c = a.*b" to be faster than <br>
three calls to PERMUTE and a call to MTIMESX, and my suspicion is that holds <br>
for any matrix size. But if you want a definitive answer on your machine <br>
with your data, time the operations yourself using TIC and TOC or the TimeIt <br>
function from the MATLAB Central File Exchange. In addition, think about the <br>
you from six months from now. Which of these two lines of code will take <br>
that you less time to understand?<br>
<br>
c =a.*b;<br>
<br>
c = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2]);<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
To contact Technical Support use the Contact Us link on <br>
<a href="http://www.mathworks.com">http://www.mathworks.com</a>

Thu, 18 Apr 2013 14:28:10 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902686
ghasem
> In addition, think about the <br>
> you from six months from now. Which of these two lines of code will take <br>
> that you less time to understand?<br>
> <br>
> c =a.*b;<br>
> <br>
> c = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2]);<br>
> <br>
>  <br>
> Steve Lord<br>
> slord@mathworks.com<br>
> To contact Technical Support use the Contact Us link on <br>
> <a href="http://www.mathworks.com">http://www.mathworks.com</a> <br>
============================<br>
I know that .* is simpler and faster.I measured three method and .* is very faster than two other method.my question was wrong.<br>
in fact I want to know that is there any method better than .* operator in 3d?<br>
ghasem

Thu, 18 Apr 2013 15:24:15 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902692
Bruno Luong
"ghasem " <shaban_sadeghi@yahoo.com> wrote in message <kkoosp$a0m$1@newscl01ah.mathworks.com>...<br>
><br>
> if I want to use from MTIMESX for fast opertaion,but second dimension of A is not equal with first diemnsion of B,but second and third dimensions in both A and B are same,is a good choice MTIMESX?<br>
> for example:<br>
> a=rand(33,32,32);<br>
> b=rand(33,32,32);<br>
> I konw that : c = mtimesx(a,b) => is false!<br>
> also,I know that simply : c =a.*b<br>
> but I want to use from:<br>
> c = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2]);<br>
> NOW,my question was:<br>
> between " .* " operator and " mtimesx (or mmx)" , which is faster?<br>
<br>
Sorry, be honest. Just admit but you don't know what is difference between matrix multiplication and pointwise multiplication.<br>
<br>
>> a=reshape(1:8,[2 2 2])<br>
<br>
a(:,:,1) =<br>
<br>
1 3<br>
2 4<br>
<br>
<br>
a(:,:,2) =<br>
<br>
5 7<br>
6 8<br>
<br>
>> b=reshape(1:8,[2 2 2])<br>
<br>
b(:,:,1) =<br>
<br>
1 3<br>
2 4<br>
<br>
<br>
b(:,:,2) =<br>
<br>
5 7<br>
6 8<br>
<br>
>> c = a.*b<br>
<br>
c(:,:,1) =<br>
<br>
1 9<br>
4 16<br>
<br>
<br>
c(:,:,2) =<br>
<br>
25 49<br>
36 64<br>
<br>
>> d = mtimesx(a,b)<br>
<br>
d(:,:,1) =<br>
<br>
7 15<br>
10 22<br>
<br>
<br>
d(:,:,2) =<br>
<br>
67 91<br>
78 106<br>
<br>
>> e = permute(mtimesx(permute(a,[2 3 1]),permute(b,[2 3 1])),[3 1 2])<br>
<br>
e(:,:,1) =<br>
<br>
16 24<br>
28 40<br>
<br>
<br>
e(:,:,2) =<br>
<br>
40 64<br>
60 88<br>
<br>
% None of the results match.<br>
<br>
Many be you should refrain asking queston until the difference is absolutly clear in your mind.<br>
<br>
Bruno

Thu, 18 Apr 2013 18:19:19 +0000
Re: MTIMESX when Inner matrix dimensions are not agree.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328414#902712
ghasem
you are right Bruno.<br>
thank you very much for your attention...<br>
my project is difficult a little and I'm confused...<br>
ghasem