loading txt files into matlab structure -


i have txt file below shown in attached figure:

a 0.15 ne 1e25 density 200 pulse_num 2 

is has n rows, 2 data on each row. first data sting contains field name, , second data contains value. 2 data separated space. how load txt file matlab structure? want like:

whatiwant = struct('a', 0.15, 'ne', 1e25, 'density', 200, 'pulse_num', 2) 

i know how load table (using readtable), , can convert table cell, structure. problem don't know how append structure. don't want input field names in code, if change field names (or don't know field names) final structure have appropriate field names.

or there other simple ways load directly?

enter image description here

this can done using:

fid = fopen('info.txt');     %opening text file c = textscan(fid, '%s%s');   %reading data fclose(fid);                 %closing text file %converting numeric data stored strings in cell numeric data using cellfun s=cell2struct(cellfun(@str2double,c{2},'un',0),c{1},1); %converting structure array 

read documentation of fopen, textscan, fclose, cellfun , cell2struct details.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -