Get variable value from imported text
Show older comments
Hello, I want to make database from the data inside my files
Here is the example of the data inside the file:

let's say I want to import the years, month, day (2020 10 3) in the first row of the data using importdata function to a matrix structure. The imported matrix is 10x1 cell in which 1 cell contains the string in 1 row. How to take just 2020 in first row string and store it in years, 10 in month, etc in the structure?
And another question, there is a table in the bottom of the data, at the example the header is in line 7. The header may be different for each file data, it may be in line 8 or 9. Is there any way to detect the header and import the data below it as a matrix structure?
edit here is attached the input data and the output example that I want
Here is the code that I tried to build:
St=struct('years',0.0,'month',0.0,'day',0.0, ...
'hours',0.0,'min',0.0,'sec',0.0);
files=dir('*-*');
N=length(files);
for i=1:N
file=files(i).name;
S=importdata(file);
St.years=S{1,1};
St.month=S{1,1};
St.day=S{1,1};
end
3 Comments
dpb
on 20 Mar 2021
Attach data file or at least a text file or code section of data, not images. Nothing can be done with them
Image Analyst
on 20 Mar 2021
No idea without the data. What do you want and want do you not want (want to ignore)? Anonymize it with generic data if you think it's too secret to post. Otherwise probably no one can help.
theo
on 20 Mar 2021
Accepted Answer
More Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!