filename input into function

38 visualizaciones (últimos 30 días)
rigel jaquish
rigel jaquish el 3 de Mzo. de 2018
Comentada: luis suarez el 22 de Sept. de 2019
Really basic question, I have just started using MatLab. I have a function that pulls specific columns out of arrays that could be in any of four data files I am working with. Thus, my goal is to input a filename, have the function load the file, and then return the specific columns. Here is my current function:
function [tlat, trate] = lss_rr(filename)
G = load(filename)
m = G(:,3)
t = G(:,4)
But when I input a filename, the name returns as an undefined variable.
  1 comentario
Rik
Rik el 3 de Mzo. de 2018
What exact code are you trying to run?

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 3 de Mzo. de 2018
[TL, TR] = lss_rr('YourFile.txt');
Change YourFile.txt to the name of your file.
Do not try to use [TL, TR] = lss_rr(YourFile.txt); as that will try to evaluate YourFile as a variable.

luis suarez
luis suarez el 20 de Sept. de 2019
When i type this command in matlab
function power_flow(filename)
Where filename is a .txt file
It says undefined variable. Can somebody help me please.
  4 comentarios
Walter Roberson
Walter Roberson el 20 de Sept. de 2019
power_flow('NameOfYourTextFileGoesHere.txt')
luis suarez
luis suarez el 22 de Sept. de 2019
Thank you very munch Mr walter Roberson it works now.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by