Clear Filters
Clear Filters

automaticaly define calibration parameter to the workspace through read the m file

4 views (last 30 days)
i have a m file, it defineed many calibration parameters one by one, each line seems like following: objDef_CAL('EngDa_jEng_C', '0.197350', 'Min', '0', 'Max', '10', 'Width', '1', 'Typedef', 'j_kgm2_t', 'Rate', 'MED','Description', 'engine inertia'); First question:how to get different part through each line, for example(Name,Min,Max,width...) second: how to define the calibration parameter to worksapce use script.

Accepted Answer

Mathieu NOE
Mathieu NOE on 20 Oct 2023
hello
maybe this ?
see my dummy calibration file attached (it's a txt and not a m file)
I simply created a second line with slightly different values (to test the code)
the code : will generate a "out" structure with fields :
out(1) = struct with fields:
EngDa_jEng_C: 0.1973
Min: 0
Max: 10
Width: 1
Typedef: ' j_kgm2_t'
Rate: ' MED'
Description: ' engine inertia'
out(2) = struct with fields:
EngDa_jEng_C: 0.4974
Min: 0
Max: 20
Width: 3
Typedef: ' j_kgm2_t'
Rate: ' MED'
Description: ' engine inertia'
D=readlines('calibration.txt'); % read as string array
lines=find(contains(D,'objDef_CAL')); % find the "objDef_CAL" line(s)
k = 0;
for ck=1:numel(lines)
tmp = char(D(lines(ck)));
% remove quote character
iq = findstr(tmp,'''');
tmp(iq) = [];
tmp = extractBetween(tmp,'(',')');
% check if line is empty or not
if ~isempty(tmp)
k = k+1;
s =split(tmp, ',');
% fill the structure "out" with info's
out(k).EngDa_jEng_C = str2double(s{2});
out(k).Min = str2double(s{4});
out(k).Max = str2double(s{6});
out(k).Width = str2double(s{8});
out(k).Typedef = s{10};
out(k).Rate = s{12};
out(k).Description = s{14};
end
end
% let's see what we have
out(1)
out(2)
  9 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!