Mike-C
Mike-C

Reputation: 43

Matlab: fprintf error

I need to save some data in a .txt file, which works great except for this one line.

%Writing the rest of the Data to the file
fprintf(fid, '%u',speedNum);
fprintf(fid, ' ');
fprintf(fid,speedUnit); %That would be the line

in speedUnit are different values (none work) one of which is: 'Frames per Min '

The error I get is:

Error using fprintf Invalid format.

Error in RackWriter>tag_OnOff_Callback (line 414) fprintf(fid,speedUnit);

Error in gui_mainfcn (line 95) feval(varargin{:});

Error in RackWriter (line 42) gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)RackWriter('tag_OnOff_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating UIControl Callback

Can somebody help me??? Thank you so much in advance

Upvotes: 0

Views: 1385

Answers (1)

serial
serial

Reputation: 437

fprintf(fid, ' ');
fprintf(fid,speedUnit);

are both function calls with only two input arguments. In the documentation of fprintf you'll find this:

fprintf(formatSpec, A1) formats data and displays the results on the screen.

So in your function calls fprintf tries to use fid as format specification. This is not possible, therefore you get an error.

fprintf(fid, '%s', ' ');
fprintf(fid, '%s', speedUnit);

should fix your problem.

Upvotes: 0

Related Questions