MATLAB: How to do this? Pass a filename to a function

#functionhandling

I have created a function to browse a file in a gui. Now I have another function which does some calculations with the variables in the browsed file. So how do I load that file's contents in the new function?

Best Answer

  • In your first function you pass the filename to the new function:
    results = new_function(filename);
    Then in new_function you read in the data and do something with it.
    function results = new_function(filename)
    data = importdata(filename); % of xlsread() or csvread() or readtable() or whatever...
    % Now do something with data....