Error using fprintf Function is not defined for 'cell' inputs

hello everyone.
im trying to save a data into .csv file but i get this error every time i press the save button.
"Error using fprintf
Function is not defined for 'cell' inputs"
CODE:
T = table(app.NEW3,app.NEW1,app.AGE1,app.Gender,app.NEW2,app.GDTT1,app.GDTT2,app.GDTT3,app.GDTT4,app.GDTT5,app.GDTT6,app.AVERAGE);
fid = fopen('Results.csv','a');
fmt = varfun(@(x) class(x),T,'OutputFormat','cell');
fmt(strcmp(fmt,'double'))={'%g'};
fmt(strcmp(fmt,'cell'))={'%s'};
fmt=[strjoin(fmt,',') '\n'];
for r=1:size(T,1)
x=table2cell(T(r,:));
fprintf(fid,fmt,x{:});
end
fclose(fid);

4 Comments

Use the debugger to find the cause of the problem:
dbstop if error
Then run the code again until it stops at the error. Now check:
class(fmt)
class(x)
cellfun(@class, x)
Without your inputs, we cannot run your code and reproduce the problem.
I’m using MATLAB app designer.. do you think this could be the case of this problem? Because when I run this code in MATLAB script I don’t receive any error.
@Oddineus: As soon as you post, what you get for the code I've posted, further statements are possible. I asked this because it helps to solve your problem.
i got this message
" Error using fprintf
Function is not defined for 'cell' inputs.
Error in Results/SaveandquitButtonPushed (line 197)
fprintf(fid,fmt,x{:});
330 throw(callbackException);
K>> "
also a script called AppManagementService opened up.

Sign in to comment.

Answers (0)

Asked:

on 9 Apr 2019

Commented:

on 9 Apr 2019

Community Treasure Hunt

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

Start Hunting!