Passing Data with structures between functions
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2015-1-20
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!