How to set matrix as variable with SetBlockParameter ?

조회 수: 1 (최근 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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by