Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: how to get multiprod working Date: Mon, 31 Jan 2011 12:00:06 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 119 Message-ID: <ii6886$6mi$1@fred.mathworks.com> References: <ihal0c$l8n$1@fred.mathworks.com> <iham08$pjm$1@fred.mathworks.com> <ihbppt$nl1$1@fred.mathworks.com> <ihc5pk$o8u$1@fred.mathworks.com> <ihddhg$hhd$1@fred.mathworks.com> <ihdng9$jbp$1@fred.mathworks.com> <ihesh7$l8f$1@fred.mathworks.com> <ihfsbb$i9u$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1296475206 6866 172.30.248.35 (31 Jan 2011 12:00:06 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 31 Jan 2011 12:00:06 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1037739 Xref: news.mathworks.com comp.soft-sys.matlab:707165 "James Tursa" wrote in message <ihfsbb$i9u$1@fred.mathworks.com>... > "Jonathan W Smith" wrote in message <ihesh7$l8f$1@fred.mathworks.com>... > > "James Tursa" wrote in message <ihdng9$jbp$1@fred.mathworks.com>... > > > "Jonathan W Smith" wrote in message <ihddhg$hhd$1@fred.mathworks.com>... > > > > > > > > I have 2 matrices A(6,6,4,24,28) and B(6,6,28) I want to do the following A(6,6,1,1,1) x B(6,6,1) ... A(6,6,4,24,28) x B(6,6,28) but only when the 5th dimension of A and 3rd dimension of B match. > > > > > > C = mtimesx(A,reshape(B,6,6,1,1,28)); > > > > > > > I was getting erroneous values for the elements in the 6x6 matrices when using multiprod. > > > > > > I am not familiar enough with multiprod to know the proper input dimensions needed to do the calculation you want in multiprod. Maybe the following will work: > > > > > > C = multiprod(A,reshape(B,6,6,1,1,28)); > > > > > > > I do not have visual basic that allows me to use mtimesx. > > > > > > MTIMESX does not need Visual Basic, or anything from Visual Studio. It can be used by anyone with any C compiler that compiles mex routines, and that includes the lcc compiler that comes shipped with MATLAB. You can build MTIMESX on a Windows system as follows: > > > > > > - Download from the FEX (I assume you have already done this) > > > - Copy the files to one of your directories that is on the MATLAB path (see Steve Lord's post). > > > - Issue the following commands: > > > > > > mex -setup > > > (Wait for the prompt, then press Enter) > > > (Select a C/C++ compiler, such as lcc) > > > mtimesx % This will cause mtimesx to self-build > > > > > > If you have a Mac or other Unix/Linux type system, the build routine is not automated. If that is the case let me know and I can try to help with this. > > > > > > James Tursa > > > > > > > > James and all, > > > > I got MEX to compile and mtimesx to work. I tried the mtimesx suggestion above but it the elements of the 6x6 matrices continued to have the erroneous values. Elements of the 6 x 6 matrices where the values should have been 0 were not. > > > > Matrix B is a column with 28 levels of 6 x 6 matrices. I each level in B contains fractions. I want to multiply these columns in B by A which for every hour (24) of everyday (4 days) has columns of 28 6 x 6 matrices. > > > > The elements of 6 x 6 matrices in A have unique values for every hour of everyday, however the 28 levels are the same. When I multiply each of level in A by their corresponding level in B each hour and level in A, the values in A are adjusted based on the based on the fraction. > > I am unaware of any bugs in mtimesx. In particular, a 6x6 matrix multiply result is obtained by a call to a BLAS library function, the same library that MATLAB itself uses. So I suspect that your problem is not really a matrix multiply problem. Can you post one of your 6x6 matrix example slices from A and B and show what result you would like to obtain? > > James Tursa James, I have 96 (24 hours for 4 days) matrices similar to the following: Columns 1 through 5 0 0 1166.7 1125 0 0 1125 2500 375 1291.7 0 1083.3 458.33 1166.7 583.33 0 0 0 0 416.67 0 0 0 0 0 0 0 0 0 0 Column 6 458.33 0 83.333 41.667 0 0 Each hour contains 28 of the matrix. In the 5-D variable apply250_km2(:,:,4,24,5), the colons are 6 x 6, the 4 is for days 1 to 4, the hours are for 0000 UTC to 2300 UTC, and the 2 is the second of 28 levels. I want to multiply apply250_km2(:,:,4,24,5) times a 3-D variable lnox_mass_frac(:,:,5) Where the colons are 6 x 6 matrices containing fractions: Columns 1 through 5 0.014881 0.015461 0.010984 0.023592 0.019761 0.020737 0.021294 0.011896 0.010486 0.015627 0.022478 0.022408 0.022339 0.022269 0.02213 0.023105 0.023035 0.022966 0.022896 0.022826 0.023523 0.023453 0.023383 0.023314 0.023244 0.023941 0.023871 0.023801 0.023732 0.023662 Column 6 0.014549 0.01629 0.02213 0.022757 0.023175 0.023592 The 5 is level 5 of 28. Essentially I want to do this apply250_km2(:,:,4,24,5) .* lnox_mass_frac(:,:,5). If the level number (1 - 28 ) does not match, I do not want to multiply it. I should attain this result: Columns 1 through 5 0 0 12.815 26.542 0 0 23.956 29.74 3.9324 20.185 0 24.276 10.239 25.981 12.909 0 0 0 0 9.5109 0 0 0 0 0 0 0 0 0 0 Column 6 6.6683 0 1.8441 0.94819 0 0 I think mtimesx and multiprod were doing the * and not .* I say this b/c the elements of the 6 x6 matrices that contain zeros in apply250_km2 should remain the same after the multiplication. This was not happening. Thanks, Jonathan