filename input into function

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 件のコメント

Rik
Rik 2018 年 3 月 3 日
What exact code are you trying to run?

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

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 3 月 3 日

0 投票

[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 2019 年 9 月 20 日

0 投票

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 件のコメント

Rik
Rik 2019 年 9 月 20 日
This is not an answer to this question. Also, this is a function definition, meaning that the variable filename will have the value with which you call the function.
luis suarez
luis suarez 2019 年 9 月 20 日
@Rik I just want to ask a question about the same problem. That is as explained above. If you know how to call the txt file please answer me. In fact the txt file consists of some bus system parameters and i want to compute the power loss.
Walter Roberson
Walter Roberson 2019 年 9 月 20 日
power_flow('NameOfYourTextFileGoesHere.txt')
luis suarez
luis suarez 2019 年 9 月 22 日
Thank you very munch Mr walter Roberson it works now.

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

カテゴリ

ヘルプ センター および File ExchangeManage Products についてさらに検索

タグ

質問済み:

2018 年 3 月 3 日

コメント済み:

2019 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by