How to read numeric data with different number of columns
I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks!I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks! I would like to read in the numeric data below into 3 different arrays:
0 0.2 0.5 0.8 into "a_on_t"
4 10 into "Ri_on_t" and
2 5 10 into "2c_on_a"
I code just hard code these in, but it would be better to read them from a file. I was thinking of constructing the file like so:
% Header info describing file contents
% Rows correspond to:
% a / t
% Ri / t
% 2c / a
0 0.2 0.5 0.8
4 10
2 5 10
or, alternatively:
% Header info describing file contents
a_on_t 0 0.2 0.5 0.8
Ri_on_t 4 10
2c_on_a 2 5 10
I would like to be able to extract the names of the arrays in which to store the data from the file and, of course, to extract the numbers from the file. As I am using R2018a I don’t have access to the table reading functions. I have tried putting the data into a cell using textscan, but I just end up with a list (or 1D array) of numbers. I definitely need the numbers, I could hard code the names of the arrays for now.
fgetl might be a possibility, but then there is the difficulty of extracting the data from a cell and converting characters to numbers.
Am I missing something obvious? This seems much more difficult than it should be.
Thanks! read text file, variable length data, mixed data types MATLAB Answers — New Questions