The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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,922
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:

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.:

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.