.. highlightlang:: us .. index:: set_ch .. _set_ch: set_ch ====== .. us.tag set_ch ENGLISH formula New570 Changed5400 Changed5511 :ref:`set_ch` sets the new channel data. The function can only be used inside a formula function. The function uses the globale variable ``_fi_ncid``. .. function:: bool = set_ch(ssChannelName, values) bool = set_ch(ssChannelName, values, ssDepChannels) bool = set_ch(ssChannelName, values, ssDepChannels, bSIUnits) .. us.return **Return Value** *bool* is TRUE (1), if the function was successful an otherwise FALSE (0). .. us.params **Parameters** .. uparam:: ssChannelName *ssChannelName* is a channel name. .. uparam:: values *values* is a vector with values. .. uparam:: ssDepChannels *ssDepChannels* is a string with the channelnames separated by a comma. If *ssDepChannels* is set to an empty string (""), the values are not set to missing, if one of the input channels contain missing values. The :ref:`ch` function returns the value ``infinite`` (1.#inf) for missing values. The :ref:`finite` function can be used to find the infinite values. See example. .. uparam:: bSIUnits *bSIUnits* must be TRUE (1), if *values* are in SI units and the ``units`` attribute is not in SI units. Teh units will be converted. If *bSIUnits* is FALSE (0) or the parameter is not specified, the units are not converted. .. us.example **Example** **Beispiel** :: // Leistung in kW // M*2*PI*n // Drehzahl n in 1/min // Moment m in Nm def _fi_Power(bInfo) { ssChannels = "n_Motor, Md_Motor"; if (bInfo) { return ["Power"; .. "kW"; .. "Leistung"; .. ssChannels; "0"]; } n_Motor = ch("n_Motor"); Md_Motor = ch("Md_Motor"); Power = (n_Motor .* Md_Motor) ./ 9549.3; set_ch("Power", Power, ssChannels); } :: // Leistung in kW // M*2*PI*n // Drehzahl n in 1/s // Moment m in Nm def _fi_Power(bInfo) { bSIUnits = 1; ssUnit = "kW"; ssChannels = "n_Motor, Md_Motor"; if (bInfo) { return ["Power"; .. ssUnit; .. "Leistung"; .. ssChannels; "1"]; } n_Motor = ch("n_Motor", "", bSIUnits); Md_Motor = ch("Md_Motor", "", bSIUnits); Power = (n_Motor .* Md_Motor) .* (2*PI); set_ch("Power", Power, ssChannels, bSIUnits); } Example for an integral calculation, where the missings are set to 0:: def _fi_qm(bInfo) { ssChannels = "time, m_flow"; if (bInfo) { return ["qm"; .. "kg"; .. "Leistung"; .. ssChannels; "1"]; } rvTime = ch("time"); rvMFlow = ch("m_flow"); idx = find(finite(rvMFlow) == FALSE); if (idx[1] != 0) { rvMFlow[idx] = 0; } // we ignore the error that the triangle before and after // the missing values is added to the integral value. rvQm = integral(rvTime, rvMFlow); // Third parameter = "": missings will not set set: // Only the second column is the integral set_ch("qm", rvQm[;2], "", FALSE); } .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2013.11 - Unit Conversion. * - R2012.0 - New documentation. * - 5.7 - New. .. seealso:: :ref:`formula-interpreter`, :ref:`ch`, :ref:`get_ncid`, :ref:`onformulastarteval` :sub:`id-875561`