Scilab not returning variables in variable window

482 views Asked by At

I have created a function that returns the magnitude of a vector.the output is 360x3 dimension matrix. the input is 360x2. Everything works fine outside the function. how do i get it to work ?

clc
P_dot_ij_om_13= rand(360,2);  // 360x2 values of omega in vectors i and j

//P_dot_ij_om_13(:,3)=0;

function [A]=mag_x(A)


//b="P_dot_ijOmag_"+ string(k);

 //execstr(b+'=[]');         // declare indexed matrix P_dot_ijOmag_k
 //disp(b)


 for i=1:1:360

     //funcprot(0);

     A(i,3)=(A(i,2)^2+A(i,1)^2)^0.5;      //calculates magnitude of i and j and adds 3rd column

    disp(A(i,3),"vector magnitude")


 end

funcprot(1);

return [A]      // should return P_dot_ijOmag_k in the variable browser  [360x3 dim]

endfunction

mag_x(P_dot_ij_om_13);


//i=1;
//P_dot_ij_om_13(i,3)= (P_dot_ij_om_13(i,2)^2+P_dot_ij_om_13(i,1)^2)^0.5;//           example
1

There are 1 answers

0
AudioBubble On

You never assigned mag_x(P_dot_ij_om_13) to any variable, so the output of this function disappears into nowhere. The variable A is local to this function, it does not exist outside of it.

To have the result of calculation available, assign it to some variable:

res = mag_x(P_dot_ij_om_13)

or A = mag_x(P_dot_ij_om_13) if you want to use the same name outside of the function as was used inside of it.

By the way, the Scilab documentation discourages the use of return, as it leads to confusion. The Scilab / Matlab function syntax is different from the languages in which return specifies the output of a function:

function y = sq(x)
  y = x^2
endfunction

disp(sq(3)) // displays 9

No need for return here.