help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: How do get a return value from a subroutine into the workspace?


From: Henry F. Mollet
Subject: FW: How do get a return value from a subroutine into the workspace?
Date: Thu, 06 May 2004 14:13:55 -0700
User-agent: Microsoft-Entourage/10.1.1.2418

I forgot to add definition of matlam.m:
function [lambda,a,surv,fecund,cuts] = matlam(dat,numclass);
cut
disp (['within matlam.m printing matrix that is called a  ' ]) % my addition
April 2004
a = surv + fecund % removed ";" to get "a"  printed to screen
% but why does matrix "a" not become available in workspace?
cut
*****
I just don't understand. I thought that I had set up the function call, so
that the matrix "a" would become available in the workspace but all I can
manage is to print it to the screen. If I type a=1 at the octave prompt, "a"
gets printed to the screen and "a" is available in the workspace. The same
principle seem to work for the main-function but it appears to be different
for a call to a sub-function within the main-function. I must be missing
something basic but cannot figure out what it is.
Henry

octave:8> load data14thTry200IndApr212004
octave:9> whos
*** local user variables:
prot  type                       rows   cols  name
====  ====                       ====   ====  ====
 rwd  matrix                      200      7  data1

octave:12> [grow_rates, kmat, mshpts] = lambda (data1, [],[],[],[],[]);
octave:13> whos
*** currently compiled functions:
cut
*** local user variables:
prot  type                       rows   cols  name
====  ====                       ====   ====  ====
 rwd  matrix                      200      7  data1
 rwd  matrix                        1      3  grow_rates
 rwd  matrix                      150    150  kmat
 rwd  matrix                      150      1  mshpts

% grow-rates, kmat, and mshptds are in workspace as expected. *So far so
good*. 

Within lambda.m there's a call to matlam.m and I've modified matlam.m so it
will print "a" to the screen and it does:

within matlam.m printing matrix that is called a
a =

  0.70000  0.00000  0.00000  0.95000  1.35000
  0.22500  0.55000  0.00000  0.00000  0.00000
  0.00000  0.40000  0.82500  0.00000  0.00000
  0.00000  0.00000  0.12500  0.92500  0.00000
  0.00000  0.00000  0.00000  0.05000  0.92500

The call for matlam.m in lambda.m was modified as follows
%mlam = matlam(dat,numclass);
[mlam,a] = matlam(dat,numclass) % added 2nd output parameter and deleted ";"
% tried several things but could not get "a" into workspace.

grow_rates = [ilam, dlam, mlam]
% grow_rates is using mlam (first return value in same call to matlam.m and
growrates becomes available in the workspace. But when trying the same for
"a" it does not work:

A_matrix = a; % Trying to get matrix called "a" into workspace
            disp ("A_matrix=")
            disp (A_matrix)




on 5/5/04 8:14 PM, Joe Koski at address@hidden wrote:

> on 5/5/04 8:38 PM, Henry F. Mollet at address@hidden wrote:
> 
>> I'm running a main program (function) with a call to a subprogram (another
>> function) that I have modified (removing ";" after the call)  so that the
>> return value ,a matrix called "A", will get printed to the screen. How do I
>> get "A" into the workspace? I have to copy/paste "A" into an editor, save it
>> as "A", then load "A" into the workspace but there must be an easier/better
>> way to accomplish this?  The return values of the main program are in the
>> workspace after running the program and they are also printed to the screen
>> if I remove the ";" after the call at the octave prompt.
>> Henry
>> 
> You set it up in the function call. For example, here's the first line of a
> function
> 
> function [A,f,tt] = hhspectrum(imf,t,l,aff)
> 
> And here is the line that gets the values A,f,tt back to the calling program
> 
> [A,f,tt] = hhspectrum(imf,t,l,0);
> 
> In the calling program, you could change the names to be different from
> those in the function, if desired, e. g.,
> 
> [B,g,ttt] = hhspectrum(imf2,tx,m,0);
> 
> It's the position in the list that matters, not the actual variable name.
> 
> Joe
> 
> 
> 
> 
> 
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------

------ End of Forwarded Message



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]