Set mask parameter with a cell array using set_param

조회 수: 1 (최근 30일)
Siegfried Rotthäuser
Siegfried Rotthäuser 2025년 3월 18일
댓글: Siegfried Rotthäuser 2025년 3월 19일
I would like to set a custom Simulink block's mask parameter with a cell array:
C = {'a', 'b'};
set_param(gcb, 'mask_parameter', C);
This fails because the third parameter to set_param() must be a string.
However, this works:
C1 = '{''a'', ''b''}';
set_param(gcb, 'mask_parameter', C1);
as well as
mx = [1,2,3];
set_param(gcb, 'mask_parameter', mat2str(mx));
How can I convert C to a string? I need something like cell2str(C).
Can anyone help please?

답변 (1개)

Voss
Voss 2025년 3월 18일
Here's a way to generate that C1 from that C
C = {'a', 'b'};
C1 = strrep(strtrim(char(formattedDisplayText(C))),'} {',', ')
C1 = '{'a', 'b'}'
C1_given = '{''a'', ''b''}';
isequal(C1,C1_given)
ans = logical
1
  댓글 수: 1
Siegfried Rotthäuser
Siegfried Rotthäuser 2025년 3월 19일
Thank you very much. Unfortunately I am unsing R2018b :( so I don't have formattedDisplayText(), but none the less, I though I was missing a simple internal function call.
I had to implement it using mat2str(), because my cell matrix consisted of strings that may contain apostrophes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by