MATLAB: How to read .txt file variable and value that are separated with ”

loadtxt

How can I read this type of .txt file and save variable names and values?
CAMERA PARAMETERS:
"Cam Structure Version" = 1
"Cam Flags" = 3
"Cam Location ID" = 0
"Cam Host Software" = software

Best Answer

s = fileread('sample.txt');
V = strsplit(s,'\n');
ss = regexp(V,'.*(?=[\=])','match');
ss = [ss{:}];
T = table;
vals = regexp(V,'(?<=[\=]).*','match');
v = vertcat(vals{:});
v1 = strtrim(v);
v2 = str2double(v1);
v3 = num2cell(v2,2);
v3(isnan(v2)) = v1(isnan(v2));
T.vals = v3;
T.Properties.RowNames = regexprep(ss,{'"'},'').';
T.Properties.VariableNames = {'Values'}
% if you want the value of Cam Structure Version for example then:
T{'Cam Structure Version',:}