Converting a text file into strings and integers

4 visualizzazioni (ultimi 30 giorni)
I have .txt input files with a very simple structure, of which I attach an example. I want to convert its content in strings and integers. My code below works, but I was wondering if there is a faster option than "textread", which seems to be the weak point.
[pattern, text, d] = textread('dataset.txt', '%s %s %d');
pattern = cell2mat(pattern(1));
text = cell2mat(text(1));
  2 Commenti

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 19 Dic 2016
Is there only the one set of values for each file? If so then probably a few fscanf() would be faster.
  3 Commenti
Paolo Binetti
Paolo Binetti il 21 Dic 2016
Thank you: 5 times faster on my sample, noticeably faster on larger files, no longer the slowest piece of code in my algorithm.

Accedi per commentare.

Più risposte (0)


Scopri di più su Cell Arrays in Help Center e File Exchange


Non è stata ancora inserito alcun tag.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by