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:
sparse is used not to work

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 26 Mar, 2011 11:57:04

Message: 1 of 26

Can you give advice,
sparse is used not to work?

m=4
n=6
RT=(zeros(n,n,m))
R=sparse([0 10 0;10 0 0;0 0 10])
for i=sparse(1:m)
    RT(:,:,i)=sparse([R zeros(3,3);zeros(3,3) R])
end

Subject: sparse is used not to work

From: Matt J

Date: 26 Mar, 2011 14:29:04

Message: 2 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imkkag$muj$1@fred.mathworks.com>...
> Can you give advice,
> sparse is used not to work?
===============

Works fine for me, or at least it's not obvious what you expected to see instead. Here's the output I got:


RT(:,:,1) =

     0 10 0 0 0 0
    10 0 0 0 0 0
     0 0 10 0 0 0
     0 0 0 0 10 0
     0 0 0 10 0 0
     0 0 0 0 0 10


RT(:,:,2) =

     0 10 0 0 0 0
    10 0 0 0 0 0
     0 0 10 0 0 0
     0 0 0 0 10 0
     0 0 0 10 0 0
     0 0 0 0 0 10


RT(:,:,3) =

     0 10 0 0 0 0
    10 0 0 0 0 0
     0 0 10 0 0 0
     0 0 0 0 10 0
     0 0 0 10 0 0
     0 0 0 0 0 10


RT(:,:,4) =

     0 10 0 0 0 0
    10 0 0 0 0 0
     0 0 10 0 0 0
     0 0 0 0 10 0
     0 0 0 10 0 0
     0 0 0 0 0 10

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 26 Mar, 2011 16:47:04

Message: 3 of 26

hai Matt J

I try to measure its capacity by using the "whos" between the use of sparse and did not, found no difference,
whether the placement of "sparse" I was wrong or in the form of "R (:,:, i)" does not need to use "sparse", please advice

Subject: sparse is used not to work

From: John D'Errico

Date: 26 Mar, 2011 17:31:04

Message: 4 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <iml5a8$8um$1@fred.mathworks.com>...
> hai Matt J
>
> I try to measure its capacity by using the "whos" between the use of sparse and did not, found no difference,
> whether the placement of "sparse" I was wrong or in the form of "R (:,:, i)" does not need to use "sparse", please advice

Sparse DOES work. However, sparse is not implemented for
n-d arrays, where n >= 3.

You can't trick it by creating sparse 2-d arrays, and merging
them together into a 3-d array. Nor does it help to use
a sparse index for your for loop.

John

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 26 Mar, 2011 18:18:05

Message: 5 of 26

thanks John D'Errico

Subject: sparse is used not to work

From: Matt J

Date: 27 Mar, 2011 02:59:05

Message: 6 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imlaks$qtj$1@fred.mathworks.com>...
> thanks John D'Errico

If you're trying to make a sparse 3D array, you might try my ndSparse class

http://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-sparse-arrays

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 27 Mar, 2011 05:03:05

Message: 7 of 26

"Matt J" wrote in message <imm95p$30c$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imlaks$qtj$1@fred.mathworks.com>...
> > thanks John D'Errico
>
> If you're trying to make a sparse 3D array, you might try my ndSparse class
>
> http://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-sparse-arrays

I've run the file, but the result error
??? Error using ==> ndSparse
Error: File: ndSparse.m Line: 1 Column: 10
A class definition must be in an "@" directory.

Error in ==> ndstest at 31
P=ndSparse(Pf(:),size(Pf)); % =Pf

Subject: sparse is used not to work

From: Nasser M. Abbasi

Date: 27 Mar, 2011 05:50:48

Message: 8 of 26

On 3/26/2011 10:03 PM, wahyoe Unggul wrote:
> "Matt J" wrote in message<imm95p$30c$1@fred.mathworks.com>...
>> "wahyoe Unggul"<wahyoe_slipnot@yahoo.co.id> wrote in message<imlaks$qtj$1@fred.mathworks.com>...
>>> thanks John D'Errico
>>
>> If you're trying to make a sparse 3D array, you might try my ndSparse class
>>
>> http://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-sparse-arrays
>
> I've run the file, but the result error
> ??? Error using ==> ndSparse
> Error: File: ndSparse.m Line: 1 Column: 10
> A class definition must be in an "@" directory.
>
> Error in ==> ndstest at 31
> P=ndSparse(Pf(:),size(Pf)); % =Pf

WHat version of Matlab do you have?

The above file uses classdef. If you have old Matlab,
it won't work.

--Nasser

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 27 Mar, 2011 06:08:04

Message: 9 of 26

Nasser M. Abbas

I use matlab 2009b
I've download it, after I ekstract ndSparse_G2__2011_02_26.zip files, I run the file ndstest.m, the results

> > ??? Error using ==> ndSparse
> > Error: File: ndSparse.m Line: 1 Column: 10
> > A class definition must be in an "@" directory.
> >
> > Error in ==> ndstest at 31
> > P=ndSparse(Pf(:),size(Pf)); % =Pf
>
> WHat version of Matlab do you have?
>
> The above file uses classdef. If you have old Matlab,
> it won't work.
>
> --Nasser

Subject: sparse is used not to work

From: Matt J

Date: 27 Mar, 2011 11:50:22

Message: 10 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <immk84$khc$1@fred.mathworks.com>...
> Nasser M. Abbas
>
> I use matlab 2009b
> I've download it, after I ekstract ndSparse_G2__2011_02_26.zip files, I run the file ndstest.m, the results
>
> > > ??? Error using ==> ndSparse
> > > Error: File: ndSparse.m Line: 1 Column: 10
> > > A class definition must be in an "@" directory.
==================

Well, this is a strange error that, as far as I can tell, has only ever been reported here:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/289652

and hasn't been resolved.

However, I've checked and rechecked that ndSparse can run on R2009b. Are you absolutely sure that that's the version you're running?

In any case, type "which ndSparse" and post the output.

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 27 Mar, 2011 14:39:05

Message: 11 of 26

"Matt J" wrote in message <imn89u$qde$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <immk84$khc$1@fred.mathworks.com>...
> > Nasser M. Abbas
> >
> > I use matlab 2009b
> > I've download it, after I ekstract ndSparse_G2__2011_02_26.zip files, I run the file ndstest.m, the results
> >
> > > > ??? Error using ==> ndSparse
> > > > Error: File: ndSparse.m Line: 1 Column: 10
> > > > A class definition must be in an "@" directory.
> ==================
>
> Well, this is a strange error that, as far as I can tell, has only ever been reported here:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/289652
>
> and hasn't been resolved.
>
> However, I've checked and rechecked that ndSparse can run on R2009b. Are you absolutely sure that that's the version you're running?
>
> In any case, type "which ndSparse" and post the output.

I've tried repeatedly, but the result is the same.
or maybe I was wrong to place the file "ndSparse".
In writing "classdef ndSparse" there is a red line which states that "Class name" ndSpase "and @ directory name do not agree: C: \ Documents and Settings \ W @ hyoe \ MyDocuments \ matlab \ ndSparse.m".
please guidance

Subject: sparse is used not to work

From: Matt J

Date: 27 Mar, 2011 14:57:05

Message: 12 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imni69$p1f$1@fred.mathworks.com>...
>
>
> I've tried repeatedly, but the result is the same.
> or maybe I was wrong to place the file "ndSparse".
> In writing "classdef ndSparse" there is a red line which states that "Class name" ndSpase "and @ directory name do not agree: C: \ Documents and Settings \ W @ hyoe \ MyDocuments \ matlab \ ndSparse.m".
===================

You'll have to change the name of the directory "W @ hyoe" to something else. You're confusing MATLAB by having directories in your MATLAB path with "@" in the name. MATLAB uses "@" to identify specific kinds of directories and treats them in a very specific way.

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 27 Mar, 2011 14:58:02

Message: 13 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imni69$p1f$1@fred.mathworks.com>...
> "Matt J" wrote in message <imn89u$qde$1@fred.mathworks.com>...
> > "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <immk84$khc$1@fred.mathworks.com>...
> > > Nasser M. Abbas
> > >
> > > I use matlab 2009b
> > > I've download it, after I ekstract ndSparse_G2__2011_02_26.zip files, I run the file ndstest.m, the results
> > >
> > > > > ??? Error using ==> ndSparse
> > > > > Error: File: ndSparse.m Line: 1 Column: 10
> > > > > A class definition must be in an "@" directory.
> > ==================
> >
> > Well, this is a strange error that, as far as I can tell, has only ever been reported here:
> >
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/289652
> >
> > and hasn't been resolved.
> >
> > However, I've checked and rechecked that ndSparse can run on R2009b. Are you absolutely sure that that's the version you're running?
> >
> > In any case, type "which ndSparse" and post the output.

hi matt
I've tried, it was able to walk.
errors that occur only in directories that I have had the name "@".
thank you very much matt

hi matt, please advice.
  if I possess the loop as below, how the placement of "ndSparse" good.

function 1:
Kel=Keg
K = zeros (ndof, ndof, nel)
for i = 1: Channel
     for j = 1: ni
         for k = 1: ni
             ij = index (i, j)
             ik = index (i, j)
             K (ij, ik, i) = keg (j, k, i)
         end
     end
end
K = (sum (K, 3))

function 2:
Kel = zeros (ni, ni, nel);
for i = 1: Channel
     E = prop (element (:, 4), 2);
     A = prop (element (:, 4), 3);
     Ex (:,:, i) = (E (i) * A (i)) / L (i) * [1 0 0 -1 0 0;
                                  zeros (2,6);
                                  -1 0 0 1 0 0;
                                  zeros (2,6)];
end

Subject: sparse is used not to work

From: Matt J

Date: 28 Mar, 2011 02:23:04

Message: 14 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imnj9q$bvj$1@fred.mathworks.com>...
>
>
> hi matt
> I've tried, it was able to walk.
> errors that occur only in directories that I have had the name "@".
> thank you very much matt
>
> hi matt, please advice.
> if I possess the loop as below, how the placement of "ndSparse" good.
======================

wayhoe, I can't understand the purpose of your code well enough to see where ndSparse would be appropriate. I cannot run your code, nor can I see which arrays are meant to be sparse.

My guess, though, is that you want to use ndSparse.build() to construct the array using info from your "index" array. Type help ndSparse.build for usage info.

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 28 Mar, 2011 04:32:05

Message: 15 of 26

"Matt J" wrote in message <imore8$m2e$1@fred.mathworks.com>...

> wayhoe, I can't understand the purpose of your code well enough to see where ndSparse would be appropriate. I cannot run your code, nor can I see which arrays are meant to be sparse.
>
> My guess, though, is that you want to use ndSparse.build() to construct the array using info from your "index" array. Type help ndSparse.build for usage info.

matt, this is my code
I tried to use to avoid the occurrence of "? Maximum variable size allowed by the program is exceeded."
in this code a lot of zeros, I intend to use "ndSparse" or "sparse" to minimize or reduce the number zero for the matrix to be efficient. please help

prop=[1 2.10e5 450 0 7.85e-5;
      2 2.20e5 800 0 7.85e-5;
      3 2.60e5 500 0 7.85e-5;
      4 2.80e5 700 0 7.85e-5]
element=[1 1 5 1 0 ;
         2 2 5 2 0 ;
         3 3 5 3 0 ;
         4 4 5 4 0 ]
index=[1 2 3 13 14 15;
       4 5 6 13 14 15;
       7 8 9 13 14 15;
       10 11 12 13 14 15]
L = 1.0e+003*[6.2048 6.2048 4.5277 4.5277]
[nel,ni]=size(index)

Cx=[0.3419 -0.3419 -0.4685 0.4685]
Cy=[0.6447 0.6447 0.8835 0.8835]
Cz=[-0.6838 -0.6838 0 0]
Cxz=[0.7645 0.7645 0.4685 0.4685]
m=size(element,1)

RT=(zeros(ni,ni,m))
for i=(1:m)
    RB=[Cx(i)/Cxz(i) 0 Cz(i)/Cxz(i);
        0 1 0 ;
        -Cz(i)/Cxz(i) 0 Cx(i)/Cxz(i)]
    RG=[Cxz(i) Cy(i) 0;
        -Cy(i) Cxz(i) 0;
        0 0 1]
    if Cxz(i)>0.001
        R=RG*RB
    else
        R=[0 Cy(i) 0;
          -Cy(i) 0 0;
          0 0 1]
    end
    
    RT(:,:,i)=[ R zeros(3,3);
             zeros(3,3) R ]
end
        
Kel=zeros(ni,ni,nel)
E=prop(element(:,4),2)
A=prop(element(:,4),3)
for i=1:nel
    Kel(:,:,i)=(E(i)*A(i))/L(i)*[1 0 0 -1 0 0;
                                 zeros(2,6);
                                 -1 0 0 1 0 0;
                                 zeros(2,6)]
end

IF=[13:1: 15]
IR=[1:1:12]
[nel,ni]=size(index)
ndof=length([IF IR])

Keg=zeros(ni,ni,nel);
for i=1:nel
    Keg(:,:,i)=RT(:,:,i).'*Kel(:,:,i)*RT(:,:,i);
end

K=zeros(ndof,ndof,nel)
for i=1:nel
    for j=1:ni
        for k=1:ni
            ij=index(i,j)
            ik=index(i,j)
            K(ij,ik,i)=Keg(j,k,i)
        end
    end
end
K=(sum(K,3))

Subject: sparse is used not to work

From: Matt J

Date: 28 Mar, 2011 15:07:03

Message: 16 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imp305$het$1@fred.mathworks.com>...
>
>
> in this code a lot of zeros, I intend to use "ndSparse" or "sparse" to minimize or reduce the number zero for the matrix to be efficient. please help
[snip]
>
> Kel=zeros(ni,ni,nel)
> E=prop(element(:,4),2)
> A=prop(element(:,4),3)
> for i=1:nel
> Kel(:,:,i)=(E(i)*A(i))/L(i)*[1 0 0 -1 0 0;
> zeros(2,6);
> -1 0 0 1 0 0;
> zeros(2,6)]
> end
====================================

For example, you could make Kel ndSparse by replacing the segment of code above by

EAL=reshape(E.*A./L.',1,1,[]);
Kel=ndSparse([1 0 0 -1 0 0;
              zeros(2,6);
              -1 0 0 1 0 0;
               zeros(2,6)] );
           
Kel=bsxfun(@times,EAL,Kel);






> K=zeros(ndof,ndof,nel)
> for i=1:nel
> for j=1:ni
> for k=1:ni
> ij=index(i,j)
> ik=index(i,j)
> K(ij,ik,i)=Keg(j,k,i)
> end
> end
> end
> K=(sum(K,3))
============================

I think you have a mistake above. Shouldn't ik=index(i,k) ??
If I assume this, then the following will generate K in ndSparse form:

I_table=cell(nel,1);
J_table=cell(nel,1);
K_table=cell(nel,1);
S_table=cell(nel,1);

for i=1:nel
    
    [jjj,kkk,sss]=find(Keg(:,:,i));
    
    idx=index(i,:).';
    
    I_table{i}=sss;
      I_table{i}(:)=i;
    J_table{i}=idx(jjj);
    K_table{i}=idx(kkk);
    S_table{i}=sss;

end
explicitCoords=cell2mat([J_table,K_table,I_table]);
explicitVals=vertcat(S_table{:});

K = ndSparse.build(explicitCoords,explicitVals,[ndof, ndof,nel]);

Ksum=full(sum(K,3));




> Keg=zeros(ni,ni,nel);
> for i=1:nel
> Keg(:,:,i)=RT(:,:,i).'*Kel(:,:,i)*RT(:,:,i);
> end
=====================

Note. Operations like these can be vectorized with MTIMESX when Kel and RT are full arrays

Keg=mtimesx(RT,'t',Kel);
Keg=mtimesx(Keg,RT);

The MTIMESX tool is available here

http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support

Recently, James told me he that he was thinking about enabling MTIMESX to work with ndSparse, but I don't know what came of that.

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 29 Mar, 2011 00:46:03

Message: 17 of 26


> > Keg=zeros(ni,ni,nel);
> > for i=1:nel
> > Keg(:,:,i)=RT(:,:,i).'*Kel(:,:,i)*RT(:,:,i);
> > end
> =====================
>
> Note. Operations like these can be vectorized with MTIMESX when Kel and RT are full arrays
>
> Keg=mtimesx(RT,'t',Kel);
> Keg=mtimesx(Keg,RT);
>
> The MTIMESX tool is available here
>
> http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support
>
> Recently, James told me he that he was thinking about enabling MTIMESX to work with ndSparse, but I don't know what came of that.

%%=================================================
hi mat
thank you very much for your help, I've change the code, and the results are very good.
Here, I just know there are many methods for preparing the matrix, and here as well, I just know what kind of loop "(:,:, n, m) ", I've read a lot of books about matlab, but have never come across this form. most widely discussed is the form of loops "(:,:)", I really like and want to learn more about preparation, preparation of the matrix and matrix reduction techniques, especially for numerical analysis, can you advise me about the reference books or other that many loops and discusses techniques for preparing a pattern matrix that is more profound, thanks in advance
I've already tried what you suggest to use "mtimesx"
but the results will occur error

... Build routine for mtimesx
... Checking for PC
... Finding path of mtimesx C source code files
... Found file mtimesx.c in E:\eploitasi\mtimesx.c
... Found file mtimesx_RealTimesReal.c in E:\eploitasi\mtimesx_RealTimesReal.c
??? Error using ==> mtimesx_build at 169
A C/C++ compiler has not been selected with mex -setup

Error in ==> mtimesx at 271
mtimesx_build;

Error in ==> tesglobal at 75
Keg=mtimesx(RT,'t',Kel)

Subject: sparse is used not to work

From: James Tursa

Date: 29 Mar, 2011 05:22:03

Message: 18 of 26

"Matt J" wrote in message <imq86n$isb$1@fred.mathworks.com>...
>
> Recently, James told me he that he was thinking about enabling MTIMESX to work with ndSparse, but I don't know what came of that.

Still on the back burner for a bit. I first needed to develop the mxGetPropertyPtr routine to support the ndSparse effort. I managed to complete that a week or two ago and am currently finishing up an mxPutPropertyPtr routine to match. Once that is done I can get back to MTIMESX.

James Tursa

Subject: sparse is used not to work

From: Matt J

Date: 29 Mar, 2011 13:54:04

Message: 19 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imra4b$anv$1@fred.mathworks.com>...
>
> hi mat
> thank you very much for your help, I've change the code, and the results are very good.
> Here, I just know there are many methods for preparing the matrix, and here as well, I just know what kind of loop "(:,:, n, m) ", I've read a lot of books about matlab, but have never come across this form. most widely discussed is the form of loops "(:,:)", I really like and want to learn more about preparation, preparation of the matrix and matrix reduction techniques, especially for numerical analysis, can you advise me about the reference books or other that many loops and discusses techniques for preparing a pattern matrix that is more profound, thanks in advance
====================


hi wahyoe. I'm not entirely sure I understand what you're looking for. In general, it is best to avoid for-loops when preparing matrices, and there are many tricks for this, depending on what kind of "pattern matrix" you are working with. For sparse matrices, it is generally best to construct using the syntax

S = sparse(i,j,s,m,n)

See "doc sparse" for more info. For other kinds of matrices, you might want to look at the GALLERY function (see "doc gallery").


> I've already tried what you suggest to use "mtimesx"
> but the results will occur error
>
> ... Build routine for mtimesx
> ... Checking for PC
> ... Finding path of mtimesx C source code files
> ... Found file mtimesx.c in E:\eploitasi\mtimesx.c
> ... Found file mtimesx_RealTimesReal.c in E:\eploitasi\mtimesx_RealTimesReal.c
> ??? Error using ==> mtimesx_build at 169
> A C/C++ compiler has not been selected with mex -setup
====================

MATLAB is asking you to designate a C/C++ compiler that you would like it to use for building MEX files. Type "mex -setup" without the quotation marks and follow instructions. You will be given a list of compilers that MATLAB detects on your machine to choose from. If you have more than one compiler, try to choose the best one.

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 29 Mar, 2011 17:29:05

Message: 20 of 26

"Matt J" wrote in message <imso9s$evl$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <imra4b$anv$1@fred.mathworks.com>...
> >
> > hi mat
> > thank you very much for your help, I've change the code, and the results are very good.
> > Here, I just know there are many methods for preparing the matrix, and here as well, I just know what kind of loop "(:,:, n, m) ", I've read a lot of books about matlab, but have never come across this form. most widely discussed is the form of loops "(:,:)", I really like and want to learn more about preparation, preparation of the matrix and matrix reduction techniques, especially for numerical analysis, can you advise me about the reference books or other that many loops and discusses techniques for preparing a pattern matrix that is more profound, thanks in advance
> ====================
>
>
> hi wahyoe. I'm not entirely sure I understand what you're looking for. In general, it is best to avoid for-loops when preparing matrices, and there are many tricks for this, depending on what kind of "pattern matrix" you are working with. For sparse matrices, it is generally best to construct using the syntax
>
> S = sparse(i,j,s,m,n)
>
> See "doc sparse" for more info. For other kinds of matrices, you might want to look at the GALLERY function (see "doc gallery").
>
>
> > I've already tried what you suggest to use "mtimesx"
> > but the results will occur error
> >
> > ... Build routine for mtimesx
> > ... Checking for PC
> > ... Finding path of mtimesx C source code files
> > ... Found file mtimesx.c in E:\eploitasi\mtimesx.c
> > ... Found file mtimesx_RealTimesReal.c in E:\eploitasi\mtimesx_RealTimesReal.c
> > ??? Error using ==> mtimesx_build at 169
> > A C/C++ compiler has not been selected with mex -setup
> ====================
>
> MATLAB is asking you to designate a C/C++ compiler that you would like it to use for building MEX files. Type "mex -setup" without the quotation marks and follow instructions. You will be given a list of compilers that MATLAB detects on your machine to choose from. If you have more than one compiler, try to choose the best one.

hi matt and james
thank you very much for your help, now everything is going well,

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 6 Apr, 2011 06:01:04

Message: 21 of 26

hai matt
how the use of "ntimesx"in the form like this
for i=1:nel
     Keg(:,:,i)=RT(:,:,i).'*Kel(:,:,i)*RT(:,:,i);
end

I've tried it, "? Assignment has more non-singleton rhs dimensions of non-singletonsubscripts Than"
thanks

Subject: sparse is used not to work

From: Matt J

Date: 6 Apr, 2011 06:17:07

Message: 22 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <ingvj0$no5$1@fred.mathworks.com>...
>
> I've tried it, "? Assignment has more non-singleton rhs dimensions of non-singletonsubscripts Than"
===============

What did you try? The code I showed you works fine for me. I get exact numeric agreement, even with

mtimesx SPEED

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 6 Apr, 2011 06:34:04

Message: 23 of 26

"Matt J" wrote in message <inh0h3$8pc$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <ingvj0$no5$1@fred.mathworks.com>...
> >
> > I've tried it, "? Assignment has more non-singleton rhs dimensions of non-singletonsubscripts Than"
> ===============
>
> What did you try? The code I showed you works fine for me. I get exact numeric agreement, even with
>
> mtimesx SPEED
to shape like this can work well
Keg (:,:, i) = RT (:,:, i) * Kel (:,:, i)
Keg = mtmexs (RT, Kel)
when the form as below, I do not understand how the placement mtimesx
  Keg (:,:, i) = RT (:,:, i). '*Kel (:,:, i) * RT (:,:, i);
thanks

Subject: sparse is used not to work

From: Matt J

Date: 6 Apr, 2011 07:00:19

Message: 24 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <inh1gs$nie$1@fred.mathworks.com>...
> "Matt J" wrote in message <inh0h3$8pc$1@fred.mathworks.com>...
> > "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <ingvj0$no5$1@fred.mathworks.com>...
> > >
> > > I've tried it, "? Assignment has more non-singleton rhs dimensions of non-singletonsubscripts Than"
> > ===============
> >
> > What did you try? The code I showed you works fine for me. I get exact numeric agreement, even with
> >
> > mtimesx SPEED
> to shape like this can work well
> Keg (:,:, i) = RT (:,:, i) * Kel (:,:, i)
> Keg = mtmexs (RT, Kel)
> when the form as below, I do not understand how the placement mtimesx
> Keg (:,:, i) = RT (:,:, i). '*Kel (:,:, i) * RT (:,:, i);
=====================

Keg=mtimesx(RT,'t',Kel);
Keg=mtimesx(Keg,RT);

Subject: sparse is used not to work

From: wahyoe Unggul

Date: 6 Apr, 2011 07:17:05

Message: 25 of 26


> Keg=mtimesx(RT,'t',Kel);
> Keg=mtimesx(Keg,RT);

me code
Keg=zeros(ni,ni,nel);

for i=1:nel
Keg=mtimesx(RT,'t',Kel);
Keg=mtimesx(Keg,RT);
end
whether there is something wrong placement
??? Error using ==> transpose
Transpose on ND array is not defined.

Error in ==> mtimesx_sparse at 67
        result = a.' * b;

Error in ==> ujibaru at 1854
Keg=mtimesx(RT,'t',Kel);

Subject: sparse is used not to work

From: Matt J

Date: 6 Apr, 2011 07:42:04

Message: 26 of 26

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <inh41h$35n$1@fred.mathworks.com>...
>
> > Keg=mtimesx(RT,'t',Kel);
> > Keg=mtimesx(Keg,RT);
>
> me code
> Keg=zeros(ni,ni,nel);
>
> for i=1:nel
> Keg=mtimesx(RT,'t',Kel);
> Keg=mtimesx(Keg,RT);
> end
> whether there is something wrong placement
=======================

(1) This shouldn't be inside a for-loop. The 2 lines

    Keg=mtimesx(RT,'t',Kel);
    Keg=mtimesx(Keg,RT);

 will internally loop over all RT(:,:,i) and Kel(:,:,i)


(2) In case you didn't understand the earlier posts, mtimesx does NOT currently support ndSparse objects. You must make RT and Kel into normal MATLAB arrays in order for it to work. Since MATLAB does not allow sparse 3D arrays, it means that both RT and Kel must both be full array types here.

Tags for 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