How do I make the names in my file header the names of the variables I load?
Date Last Modified: Monday, April 26, 2010
| Solution ID: | 1-17YYD | |
| Product: | MATLAB | |
| Reported in Release: | R11.1 | |
| Platform: | All Platforms | |
| Operating System: | All OS |
Subject:
How do I make the names in my file header the names of the variables I load?
Problem Description:
I have column headers at the top of my file and I want to name my variables in MATLAB the same names.
Solution:Assume that a file named 'mydata.txt' stores tab delimited data whose column wise contents you would like to assign to the variables with the names same as the column headers in the file. This is the contents of 'mydata.txt': Step 1: Read the column headers and data from the file.
%open file
Step 2:Convert the column headers into individual elements stored in a cell array.
headers = textscan(headerline,'%s','Delimiter','\t');
Step 3: Use EVAL statements to copy the column data into the individual
for k = 1:length(headers{:})
|
Related Solutions:
|
|
