MATLAB: Can someone help me to read the data in the attached .txt file using fscanf? Edit: Also how can I add a space to a string in a certain location

datadatetimefprintffscanfMATLABreadspacestring

The attached file has been written using fprintf. By the way, why does the text appear aligned when it's opened with notepad and not aligned when opened with matlab?
The function used to write the text file is the following:
function [] = IPC2(namefile, d, epcheck)
%This Function registers input data to a text file for further use.
global ha hp i omega OMEGA teta0
if epcheck == 3
psp = evalin('base', 'psp');
else
psp = ' ';
end
alphadate = evalin('base', 'alphadate');
fID = fopen([namefile,'.txt'],'w');
fprintf(fID,'%s \r\n', 'UNINA SPACE MAST Input File');
fprintf(fID,'%s %i', 'Input Type Identifier:', 1);
fprintf(fID,'\r\n \r\n');
header = strings(9);
v = nan(8);
u = strings(6);
header(1) = 'ha:';
header(2) = 'hp:';
header(3) = 'i:';
header(4) = 'omega:';
header(5) = 'OMEGA:';
header(6) = 'teta0:';
header(7) = 'Date & time:';
header(8) = 'alphadate:';
header(9) = 'Satellite''s entry point:';
v(1) = ha/1000;
v(2) = hp/1000;
v(3) = i*180/pi;
v(4) = omega*180/pi;
v(5) = OMEGA*180/pi;
v(6) = teta0;
v(7) = psp;
v(8) = alphadate*180/pi;
u(1) = 'km';
u(2) = 'km';
u(3) = '°';
u(4) = u(3);
u(5) = u(3);
u(6) = u(3);
u(7) = '%';
u(8) = u(3);
for ii = 1 : 6
fprintf(fID, '%s \t\t', header(ii));
fprintf(fID, '%f ', v(ii));
fprintf(fID, '%s\r\n', u(ii));
end
fprintf(fID, '\r\n');
fprintf(fID, '%s\r\n', 'GROUND TRACK INPUT');
fprintf(fID, '%s \t\t\t\t', header(7)); fprintf(fID, '%s \r\n', d);
fprintf(fID, '%s \t\t\t\t', header(8)); fprintf(fID, '%s', num2str(alphadate*180/pi));
fprintf(fID, '%s\r\n', u(8));
if epcheck == 1
ep = 'Ascending node';
end
if epcheck == 2
ep = 'Descending node';
end
if epcheck == 3
psp = num2str(psp);
ep = psp;
end
fprintf(fID, '%s \t\t', header(9)); fprintf(fID, '%s', ep);
if epcheck == 3
fprintf(fID, '%s', u(7));
end
end
In this case, epcheck == 3.
I need to get all the numbers in the text file and the datetime string

Best Answer

Preferences -> Editor/Debugger -> Tab . Set the Tab Size to 8.
8 is the traditional tab size, but it is only a convention. If you are not using a typewritter or similar device that has literal physical tab stops, and you are not using the data as input to a program such as WordPerfect or a forms editor that recognizes tab as having very specific meaning different than equivalent spaces, then you should probably not use tab.
With respect to reading the file: Except in the case that you are reading from a serial device and have programmed TAB as the end of line character, fscanf() of a serial device or a file will treat any mixture of tabs and spaces as being a single whitespace. You cannot, for example, use fscanf() with a '%s%s%f' format expecting that 'helloTABTAB3' would be read as 'hello' [] 3 .
If you need tabs to mark the end of fields with two tabs in a row marking a skipped field, then you should process the individual characters yourself, or you should use textscan() as you can call textscan with a Whitespace parameter that does not include tab and Delimiter that includes tab, and you can make sure that MultipleDelimetersAsOne is not true (default is not true.)