필터 지우기
필터 지우기

Matlab function code error

조회 수: 4 (최근 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 CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by