Importing Data from a TXT file
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alice Stembridge
il 23 Apr 2015
Modificato: Stephen23
il 24 Apr 2015
I have successfully managed to read a text file containing a large number of values, however, I am unable to use these value in MATLAB. I think this is because in the array they have apostrophe's around the numbers, for example, '0.235659'.
The code I used to read the text file and store the values in an array is:
fid = fopen('Kap.PORO');
tline = fgetl(fid);
tlines=cell(0,1);
while ischar(tline)
%disp(tline)
tlines{end+1,1}=tline;
tline = fgetl(fid);
end
fclose(fid);
I was wondering if anyone knew how to either convert these into an array where I can use the values or a better way of storing values from a TXT file.
Thanks
1 Commento
Risposta accettata
Stephen23
il 24 Apr 2015
Modificato: Stephen23
il 24 Apr 2015
The single quotes indicate that this is a cell-array of strings, where the strings contain some numeric values. Note that this is quite a different thing to a call array of numeric values:
>> {'1.2','3.4','5.6'} % cell array of strings
ans =
'1.2' '3.4' '5.6'
>> {1.2,3.4,5.6} % cell array of numeric values
ans =
[1.2000] [3.4000] [5.6000]
>> str2double({'1.2','3.4','5.6'})
ans =
1.2000 3.4000 5.6000
But the best solution is still likely to be to import the data using textscan.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Text Data Preparation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!