How to input a string in a function and then use the string original name

1 view (last 30 days)
Hello,
My need: I want to write a function, one of the inputs would be one of 20 text files. Then I want to plot the data inside the text file.
My problem: I can't find a way to write a function that loads a text file of my choice.
This is how I wrote the code that is not working, I greatly appreciate any help.
function []=MyText(TextFile)
text(1,:)=load('text123.txt') % text123 is the original file name. It was I will use to in the input when I run the function.
t=0:10;
plot(t,text)

Accepted Answer

Walter Roberson
Walter Roberson on 10 Oct 2015
function []=MyText(TextFile)
text(1,:)=load(TextFile);
t=0:10;
plot(t,text)
  1 Comment
Tarek Abdallah
Tarek Abdallah on 10 Oct 2015
Thank you! I also had to made sure when I'm running the function I input the argument as string. Much appreciated.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!