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

조회 수: 17 (최근 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 CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by