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

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -