The following two statements read the first line from an input file (fid
) and parse said line into strings delimited by whitespace.
a = textscan(fid,'%s',1,'Delimiter','\n');
b = textscan(a{1}{1},'%s');
I would like to know if this action can be accomplished in a single statement, having a form similar to the following (which is syntactically invalid).
b = textscan(textscan(fid,'%s',1,'Delimiter','\n'),'%s');
Thanks.
Instead of
you can use
That will return the next line in
fid
as a string (the newline character at the end is stripped). You can then split that line into white-space separated chunks as follows:Combined:
Note that this is not 100% equivalent to your code, since using
textscan
adds another cell-layer (representing different lines in the file). That's not a problem, though, simply useif you need that extra cell-layer.