Azzera filtri
Azzera filtri

Checking if 'C++ type stream' is valid when using Matlab Coder

2 visualizzazioni (ultimi 30 giorni)
I am using matlab coder to turn matlab code into C++. One desired function is to read a file. I can do so effectively by following the code found at:
However, I would also like to check to make sure the stream is valid. In matlab I can simply do this by saying:
fid = coder.ceval('fopen', [FileName 0], ['a+t' 0]);
if(fid~=0)...
However, currently the compiler is telling me: "??? Expected either a logical, char, int, fi, single, or double. Found a coder.opaque."
I tried a few options:
if(fid)...
if(~fid)...
if(fid==NULL)...
But could not get it to work. Any ideas?

Risposte (1)

Ryan Livingston
Ryan Livingston il 20 Feb 2013
Modificato: Walter Roberson il 20 Feb 2013
Try:
fid = coder.opaque('FILE *','NULL')
NULL = coder.opaque('FILE *','NULL');
fid = coder.ceval(...);
if(fid == NULL)
...
after adding <stdio.h> in your project as you describe in your other post:
The error you are seeing is because the line:
if(fid~=0)
is trying to compare a coder.opaque, fid, to a double, 0.

Categorie

Scopri di più su MATLAB Coder 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