How to get two arrays from .txt file?
Afficher commentaires plus anciens
Hi, I have a problem with getting two arrays from one file. I even have a problem with getting only one, sadly.
I don't know how to skip the text and what to do with '...'. I cannot modify the file in any way.
I need to get two arrays and later use them to display some graphs.
I was looking through many threads here but no solution works.
Réponse acceptée
Plus de réponses (2)
David Hill
le 25 Jan 2022
Why not just copy and paste?
dL1=[0 0.000424 0.000847 0.001271 0.001694...
0.002118 0.002541 0.002965 0.003812...
0.004659 0.005082 0.005929 0.006776...
0.009318 0.010588 0.012282 0.013129...
0.013976 0.0144];
F1=[0 1693.191 2944.681 4417.021 6625.532...
6331.064 6478.298 6183.83 6625.532 7214.468...
7435.319 7729.787 8024.255 8465.957...
8613.191 8465.957 8024.255 6920 5889.362];
1 commentaire
Mikolaj Rebacz
le 25 Jan 2022
Benjamin Thompson
le 25 Jan 2022
1 vote
textscan can handle it if you read line by line:
>> fin = fopen('arrays2.txt', 'rt')
fin =
4
>> fgets(fin)
ans =
'
'
>> fgets(fin)
ans =
'randomtext:
'
>> fgets(fin)
ans =
'
'
>> S1 = fgets(fin)
S1 =
'dL1=[0 0.000424 0.000847 0.001271 0.001694...
'
>> C = textscan(S1, 'dL1=[%f %f %f %f...')
C =
1×4 cell array
{[0]} {[4.2400e-04]} {[8.4700e-04]} {[0.0013]}
1 commentaire
Mikolaj Rebacz
le 25 Jan 2022
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!