automaticaly define calibration parameter to the workspace through read the m file
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
wenchao zhang
am 20 Okt. 2023
Kommentiert: Mathieu NOE
am 23 Okt. 2023
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.
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 20 Okt. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

