我是MATLAB的新手。我有这个代码使用gui提取图像功能。我有问题创建一个代码,可以记录提取到csv和txt文件中的数据。我希望每次将图像加载到gui时,将从图像中提取的数据记录到单个csv文件中。数据将用于训练神经网络。有人能帮我吗? TQ
%~~~~~~~~~~~~~~~~~~~~~~~~use when train data~~~~~~~~~~~~~~~~~~~~~
% stt=0; %use it when train data\\set grade value set 1 if pet, set 0 if nonpet
% humoment=[num2str(M1) ',' num2str(M2) ',' num2str(M3) ',' num2str(M4) ',' num2str(M5) ',' num2str(M6) ',' num2str(M7) ',' num2str(perimeter) ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar) ',' num2str(stt)];
% Record (humoment,'C:\MATLABDATA\datatrain.csv') %use it when train data
% %~~~~~~~~~~~~~~~~~~~~~~~~use when test data~~~~~~~~~~~~~~~~~~~~~~
humoment=[num2str(M1) ',' num2str(M2) ',' num2str(M3) ',' num2str(M4) ',' num2str(M5) ',' num2str(M6) ',' num2str(M7) ',' num2str(perimeter) ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar) ];
data= [filename ',' num2str(M1) ',' num2str(M2) ',' num2str(M3) ',' num2str(M4) ',' num2str(M5) ',' num2str(perimeter) ',' num2str(M6) ',' num2str(M7) ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar)];
Record(humoment,'C:\MATLABDATA\datatest.csv')
Record(data,'C:\MATLABDATA\datatest.txt')
set(handles.edit45,'String','Load completed')
end
答案 0 :(得分:2)
最简单的解决方案可能是替换
Record(humoment,'C:\MATLABDATA\datatest.csv')
Record(data,'C:\MATLABDATA\datatest.txt')
与
fid = fopen('C:\MATLABDATA\datatest.csv','a+');
fprintf(fid,[humoment,'\n']);
fclose(fid);
fid = fopen('C:\MATLABDATA\datatest.txt','a+');
fprintf(fid,[data,'\r\n']);
fclose(fid);