Illegal use of a matrix or vector type where a scalar was expected in Stateflow

24 visualizaciones (últimos 30 días)
My intention is to run, online, a state machine that offsets the irradiation vector and energy price vector to formulate a simple strategy only based on producing from irratiation over a threshold and keep producing from grid at the cheapest grid hours with irradiation under threshold, to supply the remain demmand, only 1 day ahead. Attached files.
First: logical indexing inside a matlab function embedded in a stateflow chart didn't work for me, I got the next error: "Non-constant expression or empty matrix". I tried using find instead of directly comparing and got the error "FIND requires variable sizing" So i had to iterate with for loops inside the funcion to find the hours of grid-connected production.
In the calculur_irr state, I only want to pre-calculate the day-ahead strategy once a day. I tried scheduled stateflows but keeping track of simulation time with the "clock" block was a disaster since the event was ignored, the once a day signal (using mod() or rem()).
So... in the calculur_irr state if you uncomment the second command, and comment the first, you'll se my final error "Illegal use of a matrix or vector type where a scalar was expected" where I tried everything, there's something I'm not seeing but I'm stuck.
The code of the embedded functions are quite simple, can someone help me?
Thanks in advance.

Respuesta aceptada

Binaya
Binaya el 16 de En. de 2024
Editada: Binaya el 16 de En. de 2024
Hi Pol Cardona
I have executed the codes you provided and came across the error: "Illegal use of a matrix or vector type where a scalar was expected".
Upon reviewing the function "future_prod_fcn" and testing all the output arguments individually:
  1. I found out that "eprice_next_day" when assigned as a vector was causing the above issue.
  2. When the simulink model is opened, all the variables are initialized into the workspace and "eprice_next_day" is initialized as a scalar.
Try the below steps:
  1. Open the provided simulink model and go to the Stateflow chart.
  2. Open "Model Explorer" from the toolstrip menu.
  3. Select "Edge to function 1" in the "Model Hierarchy" on the left side.
  4. Change the size corresponding to "eprice_next_day" to "1,24" in the "Model Explorer".
  5. Run the code and it should run without any errors.
Hope it helps!
  1 comentario
Pol Cardona Rubio
Pol Cardona Rubio el 8 de Abr. de 2024
Editada: Pol Cardona Rubio el 8 de Abr. de 2024
I solved it but I don't remember how.. But maybe your solution helps someone else. Thanks!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Complex Logic en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by