Effacer les filtres
Effacer les filtres

How to set matrix as variable with SetBlockParameter ?

5 vues (au cours des 30 derniers jours)
Matthieu
Matthieu le 3 Avr 2023
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.

Réponse acceptée

Matthieu
Matthieu le 4 Avr 2023
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 !

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by