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

22 ビュー (過去 30 日間)
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.

採用された回答

Binaya
Binaya 2024 年 1 月 16 日
編集済み: Binaya 2024 年 1 月 16 日
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 件のコメント
Pol Cardona Rubio
Pol Cardona Rubio 2024 年 4 月 8 日
編集済み: Pol Cardona Rubio 2024 年 4 月 8 日
I solved it but I don't remember how.. But maybe your solution helps someone else. Thanks!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComplex Logic についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by