How do I do this? Pass a filename to a function?

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?

 採用された回答

Image Analyst
Image Analyst 2018 年 7 月 1 日

0 投票

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....

5 件のコメント

new user 00
new user 00 2018 年 7 月 1 日
what is "results"?
Image Analyst
Image Analyst 2018 年 7 月 1 日
It's whatever variables you want to pass back to the calling routine. You don't have to use it. You can call it whatever you want or even use multiple ones, like
function [result1, result2] = new_function(input1, input2, input3)
Sounds like you need to read the Getting Started stuff about how to write a program and call functions.
new user 00
new user 00 2018 年 7 月 2 日
don't mistake me. But even now I'm not so clear with what to do. Is there any videos related to this?
Image Analyst
Image Analyst 2018 年 7 月 2 日
Stuart has an excellent collection of them here:
two of which are the second and fourth links on Stephen's list.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by