Matlab function code error
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
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 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!