How to convert a multidimensional array into an acceptable string for Simulink.Signal initialization?

I need to initialize a Simulink.Signal with a 4-D array:
Q_dro.DataType = 'double';
Q_dro.Dimensions = [101 5 61 3];
Q_dro.Complexity = 'real';
Q_dro.InitialValue = 'tmp.Q_dro';
The 'tmp.Q_dro' is the name of a 4-D array, but the Simulink.Signal.InitialValue needs string scalar as its input, so I don't know how to convert this multidimensional array into an acceptable string. Since its dimensions could be multidimension, so I guess it's actually available but I have no idea how to achive it. Hope to get answer, sincerely thanks:)

2 Commenti

Not sure if you need a Simulink.Signal object or a Simulink.Parameter object.
I've experienced at most 2-D signals (e.g. front/rear, left/right wheel speeds). Otherwise, multiple dimensional sigal comes in as a bus, which is nested in strucutre, but not in 3-D or 4-D.
Thanks for the reply!
I'm currently working on an Reinforcement Learning model which needs to load its multidimensional parameters from local .mat file and use them in a simulink function. I use Simulink.Signal object to make these data can be asserted globally and once it's been initialized it will only be changed within the body of the function. I'm new to Simulink, I will check the usage of bus and see whether it could help.
It's really a useful advice!

Accedi per commentare.

 Risposta accettata

out = cat(4, cat(3, [1 2; 3 4; 5 6], [7 8; 9 10; 11 12]), cat(3, [41 42; 43 44; 45 46], [47 48; 49 410; 411 412]))
out =
out(:,:,1,1) = 1 2 3 4 5 6 out(:,:,2,1) = 7 8 9 10 11 12 out(:,:,1,2) = 41 42 43 44 45 46 out(:,:,2,2) = 47 48 49 410 411 412
whos out
Name Size Bytes Class Attributes out 3x2x2x2 192 double
That is, it can be done as a string, using cat(4) and cat(3) . It is not very convenient.
Or... you can use
out = reshape(some vector, [101 5 61 3])
which is a lot easier to generate, but is more difficult to read and edit.

3 Commenti

Thanks for the answer:)
It indeed represents a 4-D array in a single string but may not suitable for my situation. The array I use is different at each beginning of simulation(it's Q-value table of a Q learning method, updated at each iteration), so constructing a string like this may not be easy. That's my problem to use Simulink.Signal to assert it globally so it can be used in simulink function. The initialization which needs transition of array to string seems pretty difficult. I may change my method like using bus or something else.
Thanks for the answer again!
str = "reshape(" + mat2str(Your4DArray(:)) + "," + mat2str(size(Your4DArray)) + ")";
Now you should be able to set_param or as appropriate.
That would be nice. I will try it later when I get to the computer.
Appreciate, you saved my day.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by