set_param の使い方
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
akihide toyota
le 30 Mai 2023
Commenté : akihide toyota
le 31 Mai 2023
get_param でオブジェクトから取り出した文字列を変更して set_param で格納したいのですがうまくいきません。
構文はこうです。for文でijを回しています。
tmp2_sname = get_param(bh_1st{ij}, 'Name');
tmp2_sname = extractBefore(tmp2_sname, "_");
set_param(bh_1st{ij}, 'Name', tmp2_sname);
tmp3_sname = get_param(bh_1st{ij}, 'Name');
最後の1行でエラーになります。最後から2行目でオブジェクトに格納できていないようです。
オブジェクトに格納できないのは何故でしょうか。
0 commentaires
Réponse acceptée
Atsushi Ueno
le 30 Mai 2023
’Name’ プロパティはオブジェクト名そのもの、すなわちモデル最上位からのパスを構成する名前です。従ってこれを変更した瞬間から、変更前のオブジェクト名ではアクセス出来なくなります。
>> get_param('test/Constant','Name') % 変更前のパスでアクセス
ans = 'Constant'
>> set_param('test/Constant','Name','temp') % ブロック名を'Constant'⇒'temp'に変更した
>> get_param('test/Constant','Name') % 変更前のパスでアクセス⇒出来ない
無効な Simulink オブジェクト名: test/Constant
原因:'Constant' という名前のブロックが見つかりません。
>> get_param('test/temp','Name') % 変更後のパスでアクセス
ans = 'temp'
オブジェクト名の変更に併せてパス名も変更してやればアクセス出来るはずです。
tmp2_sname = get_param(bh_1st{ij}, 'Name');
tmp2_sname = extractBefore(tmp2_sname, "_");
set_param(bh_1st{ij}, 'Name', tmp2_sname);
ext = regexp(bh_1st{ij},'(.+/)*','match'); % パス名から変更前のオブジェクト名を削除
bh_1st{ij} = [ext{1},tmp2_sname]; % パス名に変更後のオブジェクト名を追加
tmp3_sname = get_param(bh_1st{ij}, 'Name');
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur プログラムによるモデル編集 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!