Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Data Reading/Plotting: Matrix names as alpha-numeric filenames and auto-updating legend Date: Sun, 1 Jul 2012 22:39:07 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 42 Message-ID: <jsqjib$e2p$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1341182347 14425 172.30.248.48 (1 Jul 2012 22:39:07 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 1 Jul 2012 22:39:07 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 3536503 Xref: news.mathworks.com comp.soft-sys.matlab:772670 I am importing several data files and plotting data from these files on the graph (same x-values). The data consist of 2 columns - x-values in column 1 and y-values in column 2. Since there will be numerous data sets on the same graph, I must add a legend for the plots. However, I would like the legend to update automatically after more data sets to the graph. I do not know ahead of time how many data sets will be plotted on the same graph. What I can do: I can use fileparts to extract the alpha-numeric part of the filename (i.e. the part without the extension). This is the part that I must now use in the legend. My usage of fileparts: files = dir('*.dat'); for k = 1:numel(files); file=files(k).name; [pathstr,name,ext] = fileparts(file); d=importdata(file); Matrix=d.data; . . . end Problem 1: 1. ) Is there some way for me to dynamically generate the legend headings, from the filename (i.e. from the name variable)? Problem 2: I need to save each extracted data set to a matrix (n rows X 2 columns) as I extract it (from each file) and then horzcat() the n matrices (all n matrices will have the same size). CONDITION 1: I am not sure how many data files will be processed so I do not know the number of matrices, k, that will be produced. CONDITION 2: I would like to use this approach: Each c{i} is a "matrix": >> c={[1 2] [3] [4 5 6] [7 8]} c = [1x2 double] [3] [1x3 double] [1x2 double] >> horzcat(c{:}) ans = 1 2 3 4 5 6 7 8 With the 2 conditions in mind, my questions are: 2. a) Is there some way for me to store the entire file name as the matrix name? 2. b) How would I add n matrices (which have the filename as their name) to a cell comma list (like shown above)? Or is there another way to horizontally concatenate n matrices?