MATLAB Answers

Al
0

How to make variable names the same as the column headers when importing?

Asked by Al
on 15 Apr 2015
Latest activity Answered by Image Analyst
on 16 Apr 2015
Notes:
My column headings are V(001), I(B54)... There are thousands of them.
Currently if I use the import wizard, the column headers do not get used for the variable names. Matlab assigns VarName1, VarName2,...
I am importing a text file.

  4 Comments

Show 1 older comment
Thank you!. Is there a way to have Matlab remove the parenthesis? so I woud have V001, IB54 ect. or is that too difficult?
When I export the data prior to import to Matlab, I must select each item individually or all together. It is much easier to just export every column of data since there are ~3400 of them.
This is what I was trying to do but not sure where to start to remove parenthesis.
"Is there a way to have Matlab remove the parenthesis?"
  • With importdata &nbsp AFAIK: No!
  • With textscan &nbsp Yes, but it takes a some lines of code.
Questions
  • Do you really want 3400 separate variables?
  • Do you know the types of the data in each column - string or numerical?
I will not use all of the 3400 variables. The issue is the 100-200 I would use need to manually selected from a list during export. This would take a long time because they are difficult to find and you need to hold down the control key for each. Its easier just to export all 3400 and let matlab turn them all into variables, then comment out the ones I don't need.
All data are numbers.

Sign in to comment.

1 Answer

Answer by Image Analyst
on 16 Apr 2015

I think the best approach is to use readtable() so that your fields have the names of your column headers. I think it will throw out the parentheses though.

  0 Comments

Sign in to comment.