How to return loop result (string) from an mfile to another mfile(editText GUI)?

조회 수: 6 (최근 30일)
I have two mfiles. One mfile (gui.m) is gui with buttons (for browse and result) and edittext component. another mfile (function.m) with looping function. when i run function.m, i want to return the result to edittext in gui.m
in function.m:
function a = function (f)
i=f; %i is browsed image from gui.m
%this loop result that i want to call to edittext
w=[];
k=0;
for ...
w=[a b];
k=k+1;
end
end
a=w; %to return the result a as w
in gui.m:
function resultButton_Callback(hObject, eventdata, handles)
set(handles.edit5);
covImg= handles.covImg; %covImg is browsed image
G = function(covImg); %call function.m
guidata(hObject,handles);
handles.covImg = G;
imshow(handles.covImg);
looking forward for any response. thanks in advance.
  댓글 수: 4
Guillaume
Guillaume 2015년 7월 8일
This is completely aside from your question, but if your function is truly called function.m, I strongly suggest you to rename it. I'm surprise that matlab actually lets you use that name since it is a reserved keyword.
A good name for a function is something that actually describes what it does.
Ria Anggraini
Ria Anggraini 2015년 7월 9일
Guillaume, Thanks for the advice. actually the name is not function but i just want to describe that the mfile function is the mfile where the operation will execute. I changed it before to another name (identify.m) but it still doesn't work like i want.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 7월 9일
Ria - you really should post code that actually works. Your return value from this function is named a but nowhere in your function body do you actually initialize a. Should this be word instead? And if word is in fact the string text that you wish to write to your edit text box, then that is easy to do.
Suppose your function signature is
function [word] = identify(f)
and that this is saved to a file named identify.m. Now suppose you call this function from your GUI (let us say in a push button callback) as
function pushbutton1_Callback(hObject, eventdata, handles)
% initialize f
f = ...;
word = identify(f);
% update the edit text box
set(handles.edit1, 'String', word);
Is that similar to the code that you are using?
  댓글 수: 1
Ria Anggraini
Ria Anggraini 2015년 7월 9일
Hayes - Thank you so much! That's really help. Now the string successfully set to edittext.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by