Matlab function code error

3 visualizzazioni (ultimi 30 giorni)
Samah EL QASSAH
Samah EL QASSAH il 24 Giu 2016
Modificato: Steven Lord il 26 Giu 2016
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 Commenti
Torsten
Torsten il 24 Giu 2016
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 il 24 Giu 2016
@Torsten: Correct.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 24 Giu 2016
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 Commenti
Samah EL QASSAH
Samah EL QASSAH il 26 Giu 2016
This is what I get:
It's a double.
Steven Lord
Steven Lord il 26 Giu 2016
Modificato: Steven Lord il 26 Giu 2016
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?"

Accedi per commentare.

Categorie

Scopri di più su Troubleshooting in MATLAB Compiler SDK in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by