Matlab Gui帮助进行签名验证

时间:2015-01-03 04:00:48

标签: matlab

假设我创建了一个GUI,让用户从一个位置选择一个图像(浏览),然后点击偏斜按钮来计算偏度,现在当我运行程序时,我选择一个图像,它的偏斜度被计算和存储在一个文本文件中,我再次浏览另一个图像(但这次我不运行我的文件,我直接点击选择图像按钮),计算偏斜但现在上一个图像的skweness被覆盖。我想要所有imgs的偏斜我通过运行我的代码一次浏览并保存在txt文件中请帮助我 这是我的代码:

% --- Executes on button press in select_image.
function select_image_Callback(hObject, eventdata, handles)
[filename, pathname, filterindex] = uigetfile('*.jpg', 'Pick a .jpg image');
X=([pathname,filename]);
global y;
y=filename;
%display(y);

handles.y=y;
imshow(X);
axes(handles.axes1);



% --- Executes on button press in skewness.
function skewness_Callback(hObject, eventdata, handles)
% hObject    handle to skewness (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global y;
 I=imread(y);
 I2 = im2double(I);
 s=skewness(I2(:));

 display(s);



fid = fopen('pqfile.txt','w');
fprintf(fid,'skewness1=%f',s);
fclose(fid);
% this saves the skweness of the first selected image but when I select an other Images It overwrites the previous value of s.

请帮助我怀疑。

1 个答案:

答案 0 :(得分:0)

改为使用fprintf

由于您要保存以前的数据,因此应在'a'中使用'w'代替fopen

fid = fopen('pqfile.txt', 'a'); % Write to existing file but append to what is already there

请注意,您可以使用printfprintffprintf涵盖了将屏幕和文件都写入的内容。

fprintf(fid,'skewness1=%f',s);

printf(fid,'skewness1=%f',s);

另外请不要忘记关闭文件

fclose(fid);