Using LibBlockParameter() into a conditional directive %if
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (1개)
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!