フィルターのクリア

How to set matrix as variable with SetBlockParameter ?

4 ビュー (過去 30 日間)
Matthieu
Matthieu 2023 年 4 月 3 日
回答済み: Matthieu 2023 年 4 月 4 日
Hello,
I am a beginner with Simulink, and I was trying to set the OutValues of a Repeating Sequence interpolated Block to a signal I had defined in my code. For some reason, when applying the following with MySignal as a vector of the values as long as the TimeValues vector ,
model = 'MySimulinkFile' ;
simIn = Simulink.SimulationInput(model) ;
simIn = setBlockParameter(simIn,[model '/Repeating Sequence Interpolated'],'OutValues',string(MySignal)) ;
simOut = sim(simIn) ;
I get this error :
Error in 'MySimulinkFile/Repeating Sequence Interpolated': Failed to evaluate mask initialization commands.
Caused by:
  • Error using Simulink.Simulation.internal.DesktopSimHelper
  • Dimension 1 of the table in block 'MySimulinkFile/Repeating Sequence Interpolated/Lookup' has a size of 1. Each table dimension must have at least 2 elements.
Am I missing something obvious ? Let me know if the full model is needed, but it is as simple as a Repeating Sequence Interpolated block facing a Scope.
Thank you for your time.

採用された回答

Matthieu
Matthieu 2023 年 4 月 4 日
I finally found the error myself :
A = [1 2 3 4 5] ;
string(A)
ans = 1×5 string array
"1" "2" "3" "4" "5"
num2str(A)
ans = '1 2 3 4 5'
whatItNeeds = strcat('[',num2str(A),']')
whatItNeeds = '[1 2 3 4 5]'
The latter variable is what setBlockParameter needs as input to eval it into a matrix. string( ) , that I used in my example, transforms each elements of the array into a str. num2str( ) ransforms the whole array into a single str character, but misses the '[' brackets.
Hope it helps someone else !

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Attributes and Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by