Passing Data with structures between functions

3 views (last 30 days)
Joshua
Joshua on 20 Jan 2015
Commented: dpb on 20 Jan 2015
I am currently working at converting a code from fortran that uses common data blocks to Matlab. I am thinking that the best way to do this is to incorporate all the common data blocks into a common structure and pass the structure between functions as needed so that all of my functions will look like
function [] = funky(varargs, common)
and then inside each function just pull out the data I need from the structure
data_needed = common.the_meaning_of_life
Im worried however, that this method is inefficient as I will be passing the common structure through about 50 functions and may eat up memory. Is there a better way to pass the data?
  1 Comment
dpb
dpb on 20 Jan 2015
How large are the data in COMMON--is it really enough to worry over?
Unfortunately, in MATLAB there's no alternative but GLOBAL variables unless you can make the Fortran replacement routines all exist within a single m-file as a callable user function and the rest as local or nested functions. Then the global data can be kept within the file scope. But, using nested functions is very restricted as everything is global within them.
I'd consider keeping the Fortran but turn the user interface into a mex function and call it from Matlab. Then the COMMON can stay hidden and not have to redesign the (presumably) working code.

Sign in to comment.

Answers (0)

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!