How to read this file in MATLAB?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am having trouble reading the datas.
0 commentaires
Réponses (2)
Turlough Hughes
le 11 Nov 2019
You can use the following to read your into a variable D.
fid=fopen('silicon_simr1.txt');
fgetl(fid)
VarNames=fgetl(fid);
strsplit(VarNames)
c=1;
while true
data=fgetl(fid);
if data==-1
break
end
D(c,1:2)=str2num(data);
c=c+1;
end
0 commentaires
James Kennedy
le 11 Nov 2019
This data file is tricky because of the unique combination of delimiters. It does use a simple tab or a fixed space.
I was able to import the data using the MATLAB import Data GUI:
![MATLABtoolbar.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247793/MATLABtoolbar.png)
I found that a combination of two custom delimiters acting as a single delimeter worked best (three spaces: 'SpaceSpaceSpace' and five spaces:'SpaceSpaceSpaceSpaceSpace'):
![customDelimiters.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247794/customDelimiters.png)
You can either import your data directly through the GUI or use it to create a script or function. I've attached a function which was created by MATLAB which should work for your data.
Here is a plot of the data for verification:
![outputPlot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247795/outputPlot.png)
0 commentaires
Voir également
Catégories
En savoir plus sur Data Import and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!