Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Add Variable Name to Matrix
Replies: 2   Last Post: Apr 30, 2013 4:50 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,893
Registered: 12/7/04
Re: Add Variable Name to Matrix
Posted: Apr 30, 2013 4:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Wednesday, May 1, 2013 8:06:11 AM UTC+12, Richard wrote:
> I have a bunch of CSVs I need to concatenate into one file to make them manageable. But the file name of each CSV contains important data, and when I concatenate them I lose the info contained in the file name. It would be great when I import the CSVs into Matlab for me to also create a new column and auto-populate it with the name of the file (which is numerical). I can do this one by one of course:
>
>
>
> 0798.1(:,11)=0798.1
>
>
>
> but I have hundreds of CSVs and I'm sure there's a way to streamline this procedure.
>
>
>
> Any thoughts?


I think your proposed way of doing it is not the best.
The filename may look numerical, but actually when you use it as a file name, it is a string, so you should store it as an element in a cell array. Thus, in your example it would be:
filename{11}='0798.1';

Also, your scheme to add columns to a matrix will only work if the number of rows in each file is EXACTLY the same. If even one of them is different, your strategy will fail.
But that's not the end of the world.
You can use a structure array for each file, e.g.:
s(11).data



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.