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?

 Respuesta aceptada

Image Analyst
Image Analyst el 1 de Jul. de 2018
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 comentarios

new user 00
new user 00 el 1 de Jul. de 2018
what is "results"?
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 el 2 de Jul. de 2018
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 el 2 de Jul. de 2018
Stuart has an excellent collection of them here:
two of which are the second and fourth links on Stephen's list.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 1 de Jul. de 2018

Comentada:

el 2 de Jul. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by