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

4 ビュー (過去 30 日間)
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.

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 10 月 20 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 10 月 23 日
My pleasure !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by