MATLAB: Reading strings between spaces from a text file.

stringtext file

The text file 'test_text.txt' contains something like this:
2.000000e-01 3 4.230000e-0 1 2
I wanted to pick each number between the spaces in a array and later i can process them. I am able to pick what I need with the code below. So if you see in line2 'X_data' contains all strings in a array so i can access them later. But say suppose there are 100 numbers in that line in the text file and i wanted to pick X_data(90) then how do I do it without keep writing %s so many times in textscan command ? Thank you.
fid = fopen('test_text.txt','r');
X_data = textscan(fid2,'%s %s %s %s');
str = X_data(4);
fclose('fid');

Best Answer

you could use
fid = fopen('test_text.txt','r');
xdata=str2num(fgets(fid))
fclose(fid)
or you can use
M = dlmread(filename, delimiter)
or you can use
T = readtable(filename)