Wrong sized array from "To workspace"

Hello!
I am interested in using several arrays in a Matlab code. Thus, I used the "to workspace" block to convert signal values to arrays. I used the settings:
However, for some reason, I got two arrays with different dimensions:
What should I do to have correctly sized arrays?

3 comentarios

Walter Roberson
Walter Roberson el 16 de Jul. de 2023
If you have any kind off conditional execution, then different branches might have executed a different number of times.
Paul
Paul el 17 de Jul. de 2023
I think that, unless the To Workspace block is actually inside a conditionally executed subsystem, the only thing that matters is the sample time of the signal input to the To Workspace block, becasue the Sample time paramater of the To Workspace block is set to -1 (inherited).
Anne
Anne el 18 de Jul. de 2023
I find it a little bit weird because that longer array is the integration of this shorter array. Otherwise I wouldn't say that there are any conditions.

Iniciar sesión para comentar.

 Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 17 de Jul. de 2023

0 votos

Are you using a variable step solver in your model? If so, you'd need to change it to a fixed step solver.

3 comentarios

Walter Roberson
Walter Roberson el 17 de Jul. de 2023
My understanding (possibly wrong) is that when you use a variable-step solver that does not have conditional blocks, that the calculation of particular signals is effectively "pull" -- calculated when needed. An implication from that is that if you have a two different chains of blocks, that the chains will not necessarily get calculated the same number of times, so the logged signals might be different lengths.
I am not at all certain of this.
Anne
Anne el 18 de Jul. de 2023
I tried to change the sample time to the exact simulation sample time value and it looks like it worked and got an equally shaped array.
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 18 de Jul. de 2023
You'd accept the answer :)

Iniciar sesión para comentar.

Más respuestas (1)

Ali Hussein Numan
Ali Hussein Numan el 16 de Jul. de 2025

0 votos

Use fixed step solver instead of variable step solver. The data to workspace will be with the same lengnth

Categorías

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 16 de Jul. de 2023

Respondida:

el 16 de Jul. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by