Matlab: is it possible to import data from ascii file and put them in a struct? -
i have file (param.txt):
jss 2 adev 1 vers 770 jsd 1
and want put data file struct variable in workplace.
let call "p", p struct of:
field value _____ |_______ jss |2 adev |1 vers |770 jsd |1
then:
>>> p.jss ans = 2
is possible?
thanks!
yes, can use textscan
grab of parts , create cell using struct
constructor.
fid = fopen('filename.txt', 'r'); % parse out fieldnames , numbers data = textscan(fid, '%s %d'); % put strings in first row , numbers in second alldata = [data{1}, num2cell(data{2})].'; % pass fieldnames , values struct() p = struct(alldata{:}); fclose(fid);
Comments
Post a Comment