MATLAB: Array of structures in Simulink

array of structsbus editorsimulink

I'm trying to develop a Simulink model that will iterate over a number of elements in an array of structures, where it will let the same operation be performed on each of those elements. E.g: Let say that we have the array of structure "A", consisting of A(n).Name A(n).Parents A(n).Children where "n" is some integer from 1 to N. Suppose that I wish to perform the operation on each of these 1 to N, elemets, e.g. some very simple as: A(n).Name ~= A(n).Parents;
To perform this I wish to use A as a constant which shall be fed the system. Further on, the appropiate subsystem "For Iterator", can be used to iterate over the different elements in A. Thus, I've created a "Matlab function", selecting elements from A with the iterating index from the subsystem "For iterator". Hence, the output from the "Matlab function" is: A(iteration-index).Name A(iteration-index).Parents A(iteration-index).Children The signal is pushed through to a new subsystem in Simulink where the operation is performed. Since the output from the "Matlab function", is a struct, I've defined a bus-object of the same type.
However I'm not able to send the first signal A since it is an array of structs as a signal into the "For iterator" subsystem, thus I canĀ“t select the elements in the "Matlab function". I've managed to perform the iteration, if I let A be A(1) and define that signal with a bus object. But how can I define a bus object to fit an array of structs?
Thank you!
Any help is much appreciated.

Best Answer

  • I managed to solve this by putting the functionality of this in a s-function, whom calls an external c-function.
    Thank you for your help!