フィルターのクリア

Using LibBlockParameter() into a conditional directive %if

4 ビュー (過去 30 日間)
Nuria Bilbao
Nuria Bilbao 2012 年 6 月 11 日
編集済み: Andrew Small 2015 年 4 月 27 日
Hello, I am trying to use a variable read from the S-function mask within a conditional directive, but there is no way of reading it properly! This variable is POPUP type and I wrote next linesinto my TLC but even if iDataType variable seems to be string type (if values within condition are not between quotation marks, "", code generation is erroneous due to matlab error: "The == and != operators can only be used to compare values of the same type" ) I cannot find propper values to distinguish different if cases. In the example, Code Generation is correct but iDataType has always a value out of the values I expected, because it always comes out from "else". I also tryed "1", "2","3" and same strings as the ones used in the popup definition but had the same wrong response.
%assign iDataType =LibBlockParameter(DataType, "", "", 0)
%if iDataType == "1.0"
...
%elseif iDataType == "2.0"
...
%elseif iDataType== "3.0"
...
%else
...
%endif
I hope somebody can help me, and thank you in advance! Nuria

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 6 月 11 日
I'm wondering if the problem is that you need to do string comparison instead of using the == operator. Since I can't think of a way to do string comparison in TLC, I will suggest using FEVAL to call into MATLAB:
%assign iDataType =LibBlockParameter(DataType, "", "", 0)
%assign isOne = FEVAL("strcmp", iDataType, "1.0")
%assign isTwo = FEVAL("strcmp", iDataType, "2.0")
%assign isThree = FEVAL("strcmp", iDataType, "3.0")
%if isOne
...
%elseif isTwo
...
%elseif isThree
...
%else
...
%endif
  3 件のコメント
Kaustubha Govind
Kaustubha Govind 2012 年 6 月 19 日
Nuria: Could you accept my answer if it helped you? Thanks!
Nuria Bilbao
Nuria Bilbao 2012 年 6 月 20 日
Done.
Thank you!

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

その他の回答 (1 件)

Andrew Small
Andrew Small 2015 年 4 月 27 日
編集済み: Andrew Small 2015 年 4 月 27 日
I needed something similar, selecting alternative C code depending on the selection in a Popup. The error hander will stop the build if the popup's value is out of bounds (should never be, unless the mask design changes).
  • p1 was the intrinsic name of the block's mask parameter list, no %assign within the TLC file.
  • the queried popup was the first item in the list the index was 0.
%function Outputs(block, system) Output
...
%assign r_unit = LibBlockParameterValue(p1,0)
%switch(r_unit)
%case 1
...
%break
%case 2
...
%break
%default
%<LibBlockReportError(block, "Unrecognised Unit selection")>
%break
%endswitch
...
%endfunction

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by