Why I get a 3 dimensional array using to workspace block?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everybody. I have a for loop which its output is 2 by N. N can be 1000 for example. And I define this for loop inside matlab function block in simulink. When I want to get output from it, it is defined as 2 by 1000 by 51. I mean it becomes 3 Dimensional! Why this happens and how to solve it? I also saw this problem when I wanted to integrate a matlab function. I need the output be M by N, but not M by N by D.
4 commentaires
Réponses (1)
Shivam Gothi
le 4 Oct 2024
As per my understanding, you are trying to log the 2d array which is an output from MATLAB function block. But instead of being a 2D array, it is a 3D array.
Here, the third dimension is corresponding to the “time step”. That is, the 2D array may have different values at different simulation time-steps. Therefore, Simulink exports the value of 2D array at every time-step, thus making it a 3D array. For an example, suppose that the MATLAB function outputs a (2 x 3) array and simulation takes 5 time steps, then your logged data will be (2 x 3 x 5). As depicted in below figure. In your case, it is (2 x 1000 x 51), because the simulation takes 51 steps.
You cannot get rid of it. But, as a work-around, you can extract the 2D array at time step (N), from the 3D array by typing the below command in MATLAB command window.
Two_D_Array = simout(:,:,N);
% This will extract the 2D matrix at Nth time step, which is the output of
% MATLAB function.
The below given figure shows the worksace variables. We can see that the variable "Two_D_Array" is extracted and has dimention (2 x 1000)
(Note: here, the data is exported as “Array” (look inside the “save format” field found in “block parameters” of “simout” block)
I have attached the demo Simulink model containing a “MATLAB function” block, which outputs a (2 x 1000) matrix.
I hope this helps !
0 commentaires
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!