Apologise for my previous post as I posted the wrong coding. I have this error One or more output arguments not assigned during call to "readData". pls assist to let me know where to correct the error. Thanks all.
Error in ==> main at 6 [status, validity, data] = readData(OPEN,'gps-2011-10-13-15-15.log');
clear;config;data = zeros(1,1);[status, validity, data] = readData(OPEN,'gps-2011-10-13-15-15.log');index = 1;while(status ~= EOF) [status, validity, data] = readData(READ); if validity == VALID_DATA data(:,index) = data; index = index + 1; endend
===================================
Mex file
===================================
#define OPEN 0 #define CLOSE 1 #define READ 2 #define VALID_DATA 1 #define INVALID -1 #include "mex.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <matrix.h>double timestamp;int status, validity;FILE *fid; void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]){ int Op; double *status_out, *validity_out, *data_out; char data [17], buffer [256]; char *str; /*check to find out the operation required*/ if (nrhs == 2) { Op = OPEN; } else { Op = READ; } /*Different cases for different operations*/ switch (Op) { case OPEN: fid=fopen("gps-2011-10-13-15-15.log","r"); //open file as read validity = INVALID; timestamp = -1; if (fid != NULL) { status = 1; } else { status = -1; } return; case READ: while(!feof(fid)) { fgets(buffer, 255, fid); //read in the first line of the file str = strtok(buffer, ","); //get the timestamp strcpy(data, str); timestamp = atof(data); //change from char to double mexPrintf("Timestamp:%f \n",timestamp); } return; case CLOSE: fclose(fid); timestamp = -1; validity = INVALID; break; default: mexErrMsgTxt("Incorrect parameter 3."); break; } /*Passing back results*/ plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); //create an mxArray status_out = mxGetPr(plhs[0]); //get a pointer to the data status_out[0] = status; plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); validity_out = mxGetPr(plhs[1]); validity_out[1] = validity; plhs[2] = mxCreateDoubleMatrix(1,1,mxREAL); data_out = mxGetPr(plhs[2]); data_out[2] = timestamp; mxFree(status_out); mxFree(validity_out); mxFree(data_out); }
Best Answer