Matlab function code error

2 次查看(过去 30 天)
Samah EL QASSAH
Samah EL QASSAH 2016-6-24
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.

请先登录,再进行评论。

回答(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 CenterFile Exchange 中查找有关 Troubleshooting 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