Using LibBlockParameter() into a conditional directive %if
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nuria Bilbao
il 11 Giu 2012
Modificato: Andrew Small
il 27 Apr 2015
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 Commenti
Risposta accettata
Kaustubha Govind
il 11 Giu 2012
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 Commenti
Più risposte (1)
Andrew Small
il 27 Apr 2015
Modificato: Andrew Small
il 27 Apr 2015
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 Commenti
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!