How to use string for a graph legend
Show older comments
Hi All
I have a script that scans a directory for text files (they have unique names), imports all of them and then I plot each text file to it's own graph and then all of them to one graph.
I want to add a legend to the graph, and the name for each dataset is a portion of what the file name was.
I then end up with a variable, lets call it string,
string = '2016-07-12 12-28-45.txt','2016-07-12 13-22-44.txt','2016-07-12 13-54-10.txt','2016-07-12 14-27-33.txt','2016-07-12 14-59-05.txt'
How do I use that variable as a legend? If I use legend(string); it just calls one of the plots the entire string name, instead of seeing it as a comma separated list.
If I copy the data in the string and paste it into the "legend(argument)" it works just fine, I'm sure it's a data-type error. Can someone please help?
I have attached my script and two sample data files. The number of data files are not known. As you will be able to see from the code I am a Matlab newbie.
Accepted Answer
More Answers (1)
AJBotha
on 14 Jul 2016
Categories
Find more on Cell Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!