[英]How do I call a matlab variable from an S function?
我正在simulink中的S函數。 MATLAB工作空間中有一些可用變量。 我想打電話給他們。
因此在MATLAB中:
a=3;
並在S函數(用C / C ++編寫)中:
double a = CallFromMATLABWorkSpace(a); //Something like this.
我該怎么做呢? 有類似mexCallMATLAB
類的mexCallMATLAB
但尚不清楚在這種情況下應如何使用。
要從工作空間獲取數據,請使用功能mexGetVariable 。
但是,這有點不尋常。 為什么不將數據作為參數傳遞給S功能?
從我在mexCallMATLAB
的文檔以及與C ++源代碼 mexCallMATLAB
內容中可以看到,它看起來類似於以下內容:
假設您有一個MatLab函數MyDoubleFunction
,它接受一個標量雙MyDoubleFunction
值並返回一個標量雙精度值。 如果要將函數的值傳遞給4.0
並查看答案是什么,請執行以下操作:
//setup the input args
mxArray* input_args[1] = {mxCreateDoubleScalar(4.0)};
mxArray** output_args; //will be allocated during call to mexCallMATLAB
//make the call to the Matlab function
if (mexCallMATLAB( 1 /* number of output arguments */,
output_args,
1 /* number of input arguments */,
&input_args,
"MyDoubleFunction"))
{
//error if we get to this code block since it returned a non-zero value
}
//inspect the output arguments
double answer = mxGetScalar(*output_args);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.