Effacer les filtres
Effacer les filtres

Passing Data with structures between functions

1 vue (au cours des 30 derniers jours)
Joshua
Joshua le 20 Jan 2015
Commenté : dpb le 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 commentaire
dpb
dpb le 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by