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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -