Reading a text file into an array
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jack
am 7 Nov. 2020
Beantwortet: Ameer Hamza
am 7 Nov. 2020
I want to read a text file called test that contains integers into an array. I keep recieving an error. How do I read a text file into an array?

% This is the code
fileID = fopen('Test.txt','r');
formatSpec = '%d %f';
sizeA = [2 Inf];
A = fscanf(fileID,formatSpec,sizeA);
fclose(fileID);
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 7 Nov. 2020
This error can occur if MATLAB cannot fine the file Test.txt. Make sure that the file is placed in the current folder or specify the complete path to the file.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!