最简单的方法是直接在“NPCR_and_UACI”函数中构建字符串,将其设置为函数的附加输出,然后将其分配给静态文本框。
可能的替代方案是:
- 使用diary在文本文件中激活输出记录
- 逐行读取
diary文件
- 将行存储在
cellarray
- 将单元格数组设置为静态文本框的
string
您可以使用 tempname 创建一个唯一的文件名
在过程结束时,您可以删除带有delete的临时日记文件。
如果要将已删除的文件移动到recylce文件夹中,应设置recycleon。
您可以在下面找到该过程的可能实现;对此,我创建了一个“虚拟”NPCR_and_UACI 函数并“评论”了global varaibles。
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global E1;
% global E2;
E1=1;
E2=2
results=NPCR_and_UACI(E1,E2);
% Create a unique filename
tmp_file=tempname
% Activate diary recording
format long
diary(tmp_file)
% Display the output on the Command Window
disp(results)
% Turno disry off
diary off
% Open the diary file
fp=fopen(tmp_file)
% Initialize the string
res_string={};
% Initialize the row counter
cnt=0;
% Read the diary file line by line
while 1
tline = fgetl(fp);
if ~ischar(tline)
break
end
% Increment the rwo counter and store the current line
cnt=cnt+1;
res_string{cnt}=tline
end
% Close the diary file
fclose(fp)
% Enable moving the file to the recycle folder
recycle('on')
% Delete the diary file (move it in the recycle folder
delete(tmp_file)
% Setr the result string in the statictext box
set(handles.text2,'string',res_string,'horizontalalignment','left','fontname','courier')
希望这会有所帮助。
卡普拉'