Matlab function code error

2 ビュー (過去 30 日間)
Samah EL QASSAH
Samah EL QASSAH 2016 年 6 月 24 日
編集済み: Steven Lord 2016 年 6 月 26 日
Hi! Could you expalin me what this part of the code mean?
if (!mxIsDoubleScalar(prhs[1])) {
TT_MEX_ERROR("Error using ==> ttAnalogOut\nIllegal output value.");
return;
}
This is the code:
/*
* Copyright (c) 2009 Lund University
*
* Written by Anton Cervin, Dan Henriksson and Martin Ohlin,
* Department of Automatic Control LTH, Lund University, Sweden.
*
* This file is part of Truetime 2.0 beta.
*
* Truetime 2.0 beta is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Truetime 2.0 beta is distributed in the hope that it will be useful, but
* without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Truetime 2.0 beta. If not, see <http://www.gnu.org/licenses/>
*/
#define KERNEL_MATLAB
#include "../ttkernel.h"
#include "../analogout.cpp"
#include "getrtsys.cpp"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
rtsys = getrtsys(); // Get pointer to rtsys
if (rtsys==NULL) {
return;
}
// Check number and type of arguments.
if(nrhs != 2) {
TT_MEX_ERROR("Error using ==> ttAnalogOut\nWrong number of input arguments.");
return;
}
if (!mxIsDoubleScalar(prhs[0])) {
TT_MEX_ERROR("Error using ==> ttAnalogOut\nIllegal output channel.");
return;
}
if (!mxIsDoubleScalar(prhs[1])) {
TT_MEX_ERROR("Error using ==> ttAnalogOut\nIllegal output value.");
return;
}
int outpChan = (int) *mxGetPr(prhs[0]);
double value = *mxGetPr(prhs[1]);
ttAnalogOut(outpChan, value);
}
  2 件のコメント
Torsten
Torsten 2016 年 6 月 24 日
My guess is:
If prhs[1] is not a scalar of type double, print the following error message:
Error using ==> ttAnalogOut
Illegal output value.
Best wishes
Torsten.
James Tursa
James Tursa 2016 年 6 月 24 日
@Torsten: Correct.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 24 日
As discussed in your previous question where I already told you that the code was testing for the input to be a scalar double, what you need to do is to add the code
disp(size(data.u))
disp(class(data.u))
before the ttAnalogOut call, and tell us what output was produced.
  2 件のコメント
Samah EL QASSAH
Samah EL QASSAH 2016 年 6 月 26 日
This is what I get:
It's a double.
Steven Lord
Steven Lord 2016 年 6 月 26 日
編集済み: Steven Lord 2016 年 6 月 26 日
The function mxIsDoubleScalar asks two questions. Only if the answers to BOTH questions are "yes" does the function return true.
A 0-by-0 double array answers "yes" to the question "Are you a double array?"
A 0-by-0 double array answers "no" to the question "Are you a scalar?"
Only 1-by-1 arrays answer "yes" to the question "Are you a scalar?"

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

カテゴリ

Help Center および File ExchangeTroubleshooting in MATLAB Compiler SDK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by