Integrate function in an interval of time into simulink function block

3 次查看(过去 30 天)
ok, i have this vector G generated by a code , and it represent the solar radiation over all the year; so it's a kind of periodic function. This code is inside a function block in simulink, i put the final part of the code.
....if (h<h_S && h>-h_S) % if true is day
G=Gdr+Gdf+Grf; % [w/m^2] radiazione globale su una superficie comunque orientata
else
G=0;
end
end
This vector G, has 365*24*3600 elements, as well the time vector t.
What i need to do is to integrate this vector G, for each month separately.
For the whole month of January it will be from 0 to (3600*24*31)th element,and for february, for example, from (3600*24*31)th to (3600*24*59)th.
So for the 1st day of january, for example, i tried to integrate from the 1st value until the 86400 th,that rapresent in second the whole day:3600*24.
i tried with
for i=1:86400
Gen=integral(G,1,86400);
end
where t is the time vector of the whole year, so of 365*24*3600 elements.
The program get this error:
"The function 'integral' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
Function 'MATLAB Function1' (#23.2558.2571), line 73, column 11: "integral(G,t)"
Alternatively, i was thinking to generate a vector for each month, using
Gen=G(1:86400)
But the program says: "Index exceeds array dimensions. Index value 2 exceeds valid range [1-1] of array G. Error in 'radiazione_totale/MATLAB Function1' (line 73) Gen=G(1:86400);"
Can you help me please?
thanks
  1 个评论
Jan
Jan 2017-10-20
The code does not work. What is the purpose of this line:
h(i)<h_alba(i) && h(i)>-h_alba(i)
? Perhaps an "if" is missing?
The body of the loop in the second code does not depend on the loop counter i. So what is "G(t)"?
Whenever you mention an error, post the complete message. Without the message and without a running code, the readers have to guess, what the problem could be.
Please edit the question and insert more details.

请先登录,再进行评论。

采纳的回答

Julia Antoniou
Julia Antoniou 2017-10-25
Hi Matteo,
The error you receive when using the "integral" function in your MATLAB function block is due to the fact that the "integral" function is not supported for code generation. If a function is not supported for code generation, it cannot be used in a MATLAB function block. The following link has an alphabetical list of all the functions that are supported for code generation and can therefore be used in MATLAB function blocks: https://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation-alphabetical-list.html
You can still use functions that are not supported for code generation in MATLAB function blocks using the "coder.extrinsic" command. However, declaring a function as "coder.extrinsic" has its limitations. You could read more about this option and see examples of how to use it on the following documentation page: https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html?s_tid=doc_ta#brdjlmz-4
Based on my understanding of your question, I do not believe the "integral" function is well suited to your case. It seems that you are trying to integrate numeric data, whereas the "integral" function is used to integrate a function. See the following documentation page to learn how to integrating numeric data in MATLAB: https://www.mathworks.com/help/matlab/math/integration-of-numeric-data.html
In reference to the second error - based on my understanding, your "G" is a 2D vector with 365*24*3600 rows and 2 columns (one for the time, and one for the value of solar radiation at that time). If you would like to pull one months' worth of data from "G" and assign it to "Gen", use the following syntax:
>> Gen=G(1:86400,:);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Schedule Model Components 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by