MATLAB: Trouble with fprintf…

exportfprintfguisprintftext file

I need to export data from my GUI to a .txt file. Example of my code below…
[filename, pathname] = uiputfile(efilename,'Save file name');
fullname = fullfile(pathname,filename);
con1e = getappdata(handles.process_condition1,'con1e_app1');
[r1 c1]=size(con1e);
for i=1:c1, fprintf(fullname,'%d,',con1e(1,i)); end
'con1e' contains all the values that I need to export (processed in a separate callback) to a .txt file. Is there a way to use 'con1e' to write my data to the .txt file? It says it can not process cell arrays. There are ~50 values in 'con1e'…. I would like to avoid having to export/import each value in the callback separately if possible. Does uiputfile take the place of fopen? Am I missing fopen and fclose? I'm not getting an error for it. Would sprintf work better? I don't understand the difference between the two… sprintf writes strings and fprintf doesn't? Any help would be greatly appriciated. Thanks!

Best Answer

You still need FOPEN. UIPUTFILE only gets the name and location for you, which you could use with FOPEN.
fid = fopen(fullname,'wt');
What does the data look like in con1e? You say con1e is a cell array, but what do the cells look like? Are they all the same format of data? Give a short example.
%
%
%
%
%
EDIT Adding an example based on comments and clarifications.
Here is an example that works on my machine:
[filename, pathname] = uiputfile('*.txt','Save file name');
fullname = fullfile(pathname,filename);
fid = fopen(fullname,'wt');
con1e = {'2' 'pizza' '777' '888' '999' 'truth' 'triumph'};
[r1 c1] = size(con1e);
for ii=1:c1,
fprintf(fid,'%s,',con1e{ii});
end
fseek(fid,-1,0);
fprintf(fid,'\n') % Get rid of last comma...
fclose(fid);