set uitable in a function matlab

1 view (last 30 days)
i have function call fungsiocr, this is my code to call that function
kandidatpelat=struct(a(11,:),value{1},a(12,:),value{2},a(13,:),value{3},a(14,:),value{4});
[ykandidatpelatf11 xkandidatpelatf11]=size(kandidatpelat.f11);
[ykandidatpelatf12 xkandidatpelatf12]=size(kandidatpelat.f12);
if((ykandidatpelatf11>0) && (xkandidatpelatf11>0))
Fungsiocr(kandidatpelat.f11,handles.mpengujiana1);
end
if((ykandidatpelatf12>0) && (xkandidatpelatf12>0))
Fungsiocr(kandidatpelat.f12,handles.mpengujiana2);
end
and my code in a function
function colorImage=Fungsiocr(datacitrargb,dataaxes)
colorImage=datacitrargb;
results = ocr(colorImage,'CharacterSet','0123456789QWERTYUIOPLKJHGFDSAZXCVBNM');
final_output=[];
final_output=[final_output deblank(results.Text)];
axes(dataaxes);
imshow(Img_Awal);
title(strcat('Detected Text : ',final_output));
i want to set database in that function with this code
%%Database
data_plat = load('Data_Plat.mat');
Database_All = data_plat.Database_All;
data2 = table2cell(Database_All(strcmpi(Database_All.Plat, final_output), ...
{'Plat', 'Nama', 'Jurusan', 'Status'}));
data2 = [get(handles.uitable1, 'Data'); data2];
data2(all(cellfun('isempty',data2),2),:) = [];
[~,idx]=unique(cell2table(data2),'rows');
unique_data2 = data2(idx,:);
set(handles.uitable1, 'Data', unique_data2);
the question is, how can i do that?, that always get error Undefined variable "handles" or class "handles.uitable1", because i want put that code in a function, any suggestion what can i do to solve my problem?? i want to procces every data to always set up in table when i call that function

Accepted Answer

Image Analyst
Image Analyst on 30 Oct 2017
Edited: Image Analyst on 30 Oct 2017
If you're using GUIDE, then all callbacks (what gets executed when you interact with some control on the GUI) will automatically have access to handles. If you don't have it, then you must have deleted it from the input argument list, or called "clear" in the callback function itself.
OTHER (non-callback) functions will not automatically have access to the handles structure variable. To get them to have access, you have to pass in handles to them when you call the functions. Of course the calling function must also have access to handles, such as the caller being a callback function or a custom user-written function that has had handles passed into it. For example, you have a push button callback function call a function Fungsiocr() which is your last chunk of code:
[colorImage, handles] = Fungsiocr(handles, datacitrargb, dataaxes)
Make sure you change the function definition of Fungsiocr() to include handles as the first input argument.
You don't need to pass handles back out if you call guidata() inside Fungsiocr() since that will update handles so that other, later functions will see the changes you made. Otherwise, if you don't call guidata() in Fungsiocr(), then pass handles back out and some other function will eventually call it.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!