Bug or restriction with matrices?

classic Classic list List threaded Threaded
8 messages Options
Lucio Agostinho Rocha Lucio Agostinho Rocha
Reply | Threaded
Open this post in threaded view
|

Bug or restriction with matrices?


Hi,

I'm working with matrices and I observed this strange behavior. I'd like to acquire as result a matrix with ten lines and ten columns. Then, I tried two things:

//---Start program
clear;
m=zeros(10,10);
function [] = test()
   
  test1(m);
 
  m(5,1)=1;
  disp(m);
endfunction

function [] = test1(m)
 
  m(5,1)=1;
  disp(m);
 
endfunction

//---End program

When I use 'test1' function I acquire the expected result, but when I use only 'test' function, considering 'm' as global, the attribution 'cut' my matrix. Why this occurs?

Thanks in advance,

Lucio
.....


      Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

Samuel GOUGEON-3 Samuel GOUGEON-3
Reply | Threaded
Open this post in threaded view
|

Re: Bug or restriction with matrices?

----- Message d'origine -----
De : Lucio Agostinho Rocha
Date : 05/06/2009 04:35:

> Hi,
>
> I'm working with matrices and I observed this strange behavior. I'd like to acquire as result a matrix with ten lines and ten columns. Then, I tried two things:
>
> //---Start program
> clear;
> m=zeros(10,10);
> function [] = test()
>    
>   test1(m);
>  
>   m(5,1)=1;
>   disp(m);
> endfunction
>
> function [] = test1(m)
>  
>   m(5,1)=1;
>   disp(m);
>  
> endfunction
>
> //---End program
>
> When I use 'test1' function I acquire the expected result, but when I use only 'test' function, considering 'm' as global, the attribution 'cut' my matrix. Why this occurs?
>
> Thanks in advance,
>
> Lucio
>  
Hello Lucio,

The "m" in the test1(m) prototype is a local copy of the expected argument.
Then, when you run test1() without argument, no m matrix is copied
(and a bit surprisingly, no error occurs). So, the m(5,1)=1 statement
creates the m from scratch, as a minimal object, here a column of 5
lines with 1 at the fifth one, and by default 0 on previous lines.
In the test() definition, writing m(1,4)=1  will then display the  0 0 0 1
line-vector instead.

It is the same in the test() definition: The test1(m) statement does not
modify m (that is a copy of the one from the calling level), since test1()
has no output argument. It just displays it.
The following m(5,1)=1; statement modifies the local copy of m,
that you display just after that, with the expected output.
The m matrix of the calling level is not modified (always only zeros).

HTH
Regards
Samuel


Samuel GOUGEON-3 Samuel GOUGEON-3
Reply | Threaded
Open this post in threaded view
|

Re: Bug or restriction with matrices?

----- Message d'origine -----
De : Samuel GOUGEON
Date : 05/06/2009 12:04:
.../...
The "m" in the test1(m) prototype is a local copy of the expected argument.
Then, when you run test1() without argument, no m matrix is copied
(and a bit surprisingly, no error occurs). So, the m(5,1)=1 statement
creates the m from scratch, as a minimal object, here a column of 5
lines with 1 at the fifth one, and by default 0 on previous lines.
In the test() definition, writing m(1,4)=1  will then display the  0 0 0 1
line-vector instead.
Sorry, mistake: In the test1() définition, writing m(1,4)=1; ..etc

Daniele Andreucci Daniele Andreucci
Reply | Threaded
Open this post in threaded view
|

Re: Bug or restriction with matrices?

In reply to this post by Lucio Agostinho Rocha
Lucio Agostinho Rocha wrote on 06/05/09 04:35:

> Hi,
>
> I'm working with matrices and I observed this strange behavior. I'd like to acquire as result a matrix with ten lines and ten columns. Then, I tried two things:
>
> //---Start program
> clear;
> m=zeros(10,10);
> function [] = test()
>    
>   test1(m);
>  
>   m(5,1)=1;
>   disp(m);
> endfunction
>
> function [] = test1(m)
>  
>   m(5,1)=1;
>   disp(m);
>  
> endfunction
>
> //---End program
>
> When I use 'test1' function I acquire the expected result, but when I use only 'test' function, considering 'm' as global, the attribution 'cut' my matrix. Why this occurs?
>
> Thanks in advance,
>
> Lucio
> .....
>
>
Dear Lucio,

was it because you did not declare

global m;

inside test?

This way it works for me.


If you also declare

global m;

in the main program, m is changed globally.



Daniele



--
[ Daniele Andreucci
[ Dip. di Metodi e Modelli Matematici
[ via A. Scarpa 16     00161 Roma, Italy
[ tel.    +39 0649766785
[ fax     +39 064957647
[ e-mail:  [hidden email]
[ http://www.dmmm.uniroma1.it/~andreucci/
[ gpg pub key id: D3ADC732


signature.asc (197 bytes) Download Attachment
Lucio Agostinho Rocha Lucio Agostinho Rocha
Reply | Threaded
Open this post in threaded view
|

Is there a Angle Histogram in Scilab?

In reply to this post by Lucio Agostinho Rocha
Hi,

I want to plot a Angle Histogram, similar of rose function in Matlab. Someone could help me?

Again, thanks in advance,

Lucio
.....


      ____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

Vergnes Nicolas Vergnes Nicolas
Reply | Threaded
Open this post in threaded view
|

RE: Is there a Angle Histogram in Scilab?

Hi,
You can see a nice example here :
http://matplotlib.sourceforge.net/examples/pylab_examples/polar_bar.html 

Regards,
 
        Nicolas Vergnes
        Produits & Logiciels Cnes
        3IRT/AP /POL


-----Message d'origine-----
De : Lucio Agostinho Rocha [mailto:[hidden email]]
Envoyé : mardi 29 septembre 2009 14:56
À : [hidden email]
Objet : [scilab-Users] Is there a Angle Histogram in Scilab?

Hi,

I want to plot a Angle Histogram, similar of rose function in Matlab. Someone could help me?

Again, thanks in advance,

Lucio
.....


      ____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com

Vergnes Nicolas Vergnes Nicolas
Reply | Threaded
Open this post in threaded view
|

RE: Is there a Angle Histogram in Scilab?

Oops a mistake, it's not for the good mailing lists..
I dont know the function to this on scilab.


-----Message d'origine-----
De : Vergnes Nicolas [mailto:[hidden email]]
Envoyé : mardi 29 septembre 2009 15:53
À : [hidden email]
Objet : RE: [scilab-Users] Is there a Angle Histogram in Scilab?

Hi,
You can see a nice example here :
http://matplotlib.sourceforge.net/examples/pylab_examples/polar_bar.html 

Regards,
 
        Nicolas Vergnes
        Produits & Logiciels Cnes
        3IRT/AP /POL


-----Message d'origine-----
De : Lucio Agostinho Rocha [mailto:[hidden email]]
Envoyé : mardi 29 septembre 2009 14:56
À : [hidden email]
Objet : [scilab-Users] Is there a Angle Histogram in Scilab?

Hi,

I want to plot a Angle Histogram, similar of rose function in Matlab. Someone could help me?

Again, thanks in advance,

Lucio
.....


      ____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com

Pierre LANDO Pierre LANDO
Reply | Threaded
Open this post in threaded view
|

Re: Is there a Angle Histogram in Scilab?

In reply to this post by Lucio Agostinho Rocha
Lucio Agostinho Rocha says : "Is there a Angle Histogram in Scilab?"

As I know no, but you can use xfarcs

******
function AngleHistogram(R,A,E,C)
  plot2d(0,0,-1,"031"," ",[-1,-1,1,1]);
  arcs=[-R;R;2*R;2*R;(A-E/2)*64;E*64];
  xfarcs(arcs,C);
endfunction


R=[.7,.5,.6]        // radius
A=[12,225,136]    // theta
E=[42,25,36]        // opening angle
C=[3,4,5]        // color


AngleHistogram(R,A,E,C)
******

--
-------------------------
Pierre LANDO
Ingénieur de développement
-------------------------
Consortium Scilab
Digiteo
Domaine de Voluceau
Rocquencourt - B.P. 105
78153 Le Chesnay Cedex France
Tél. : +33.1.39.63.58.21