Opening Multiple Gui Problem

2 views (last 30 days)
Hi,
I have finished a gui project. It has two button. One of them to get excel file the other one is for to calculation. When i push the second button five more interface open on the background. What is the main reason of this and how can I solve it?
  3 Comments
Onur ALPAY
Onur ALPAY on 1 Mar 2020
% --- Executes on button press in PVD.
function PVD_Callback(hObject, eventdata, handles)
% hObject handle to PVD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of PVD
if get(hObject,'Value')==get(hObject,'Max')
PVD=1;
CVD=0;
save PVD;
save CVD;
else
PVD=0;
CVD=1;
save PVD;
save CVD;
end
%--- Executes on button press in CVD.
function CVD_Callback(hObject, eventdata, handles)
% hObject handle to CVD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of CVD
if get(hObject,'Value')==get(hObject,'Max')
CVD=1;
PVD=0;
save CVD;
save PVD;
else
CVD=0;
PVD=1;
save CVD;
save PVD;
end
% --- Executes on button press in F1_checkbox.
function F1_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to F1_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of F1_checkbox
% --- Executes on button press in F2_checkbox.
function F2_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to F2_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of F2_checkbox
% --- Executes on button press in F6_checkbox.
function F6_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to F6_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of F6_checkbox
% --- Executes on button press in K1_checkbox.
function K1_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to K1_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of K1_checkbox
% --- Executes on selection change in recete_popupmenu.
function recete_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to recete_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns recete_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from recete_popupmenu
val = get(hObject,'Value');
switch val
case 1
disp('Reçete Seçin');
case 2 %ASEL104
IAS=11;
DosyaAdi='ASEL104';
save IAS; %IAS, İşlem Adım Sayısını Tutan Değişken
save DosyaAdi;
case 3 || 4 %Umtas İçbükey ve Umtas Dışbükey
IAS=10;
save IAS;
case 5
IAS=7; %ZnSe_Koruma
DosyaAdi='Znse_Koruma';
save IAS;
save DosyaAdi;
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function recete_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to recete_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in VeriSec.
function VeriSec_Callback(hObject, eventdata, handles)
% hObject handle to VeriSec (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
NA='#N/A';
NAA=str2num(NA);
IslemAdimSayisi=[]; %Hangi islem adiminin kaç defa yazdigini tutacak dizi
ShutterDizisi=[107,108,109,110,148,154,160,166,235,236];
ShutterMatrisi=[];
MinBasincDizisi=[];
MinSicaklikDizisi=[]; MaxSicaklikDizisi=[];
RateAverageDizisi=[];
Aps1CoilCurrentMaxDizisi=[]; Aps1CoilCurrentAverageDizisi=[];
Gas1MinDizisi=[]; Gas1MaxDizisi=[];
Gas2MinDizisi=[]; Gas2MaxDizisi=[];
KalinlikDizisi=[];
kap=0;
[FileName,FilePath]=uigetfile('*.xlsx');
if isequal(FileName, 0)
disp('Lütfen Veri Seçin.');
return;
end
warndlg('Veri alınıyor. Lütfen bekleyin...','DİKKAT!','modal');
KontrolVeri=xlsread(fullfile(FilePath,FileName));
save KontrolVeri;
yukleme_cubugu=waitbar(0,'İşlem tamamlandı. Lütfen, bekleyin…');
for i=1:1:2000 % bir üstteki sat?r ile waitbar nesnesi olu?turuluyor.
% uygulaman?n yüklenmesi s?ras?nda yer alan i?lemler
waitbar(i/100,yukleme_cubugu ); % olu?turulmu? waitbar nesnesinin günc.
end
close(yukleme_cubugu)
disp('Veri Al?nd?. Hesapla butununa bas?n.');
% --- Executes on button press in VeriSec.
function Hesapla_Callback(hObject, eventdata, handles)
% hObject handle to VeriSec (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load IAS;
load PVD;
load CVD;
load KontrolVeri;
if PVD==1 && CVD==0
IslemAdimiSutunu=KontrolVeri(:,17); %PVD excel veri tablosunda R sutununu (ACT_PROCSTEPNO) buraya atar
IslemAdimiSayisiMax=max(IslemAdimiSutunu); %PVD excel veri tablosunda R sutunundaki maksimum değeri atar
IslemAdimiSayisiMax1=IslemAdimiSayisiMax; %As?l islem ad?m say?s?n? tutar
IslemAdimiSayisiMax=IslemAdimiSayisiMax+1; %Veri dosyası içinde 0'da işlem adımı olarak verildiği için max işlem adımı 1 arttırıldı
IslemAdimiSayisiMin=min(IslemAdimiSutunu); %PVD excel veri tablosunda R sutunundaki minimum değeri atar
VeriSatirUzunluk=length(IslemAdimiSutunu);
for i=1:IslemAdimiSayisiMax %islem adimlarinin satir araliklerini bulan for dongusu
adet=0; %Hangi islem adimi sayisindan kac adet olduğunu tutan sayac
IslemAdimSayisi(1,i)=i-1; %İslem adimlarini sirasiyla "IslemAdimSayisi" dizisinin 1. satirina atama islemi
for j=1:VeriSatirUzunluk %1'den "VeriSatirUzunluk" kadar veriyi işleme sokan hangi islem adiminden kac tane oldugu hesaplanıyor
if IslemAdimiSutunu(j)==IslemAdimiSayisiMin
adet=adet+1;
end
IslemAdimSayisi(2,i)=adet;
end
IslemAdimiSayisiMin=IslemAdimiSayisiMin+1;
end
SatirMin=2; %Cihazın verdiği veri tablosunda ilk satır başlıklardan oluştuğu için
%ikinci satırdan satır saymaya başlaması gerekiyor
SatirMax=SatirMin+IslemAdimSayisi(2,1)-1;
SatirMin=SatirMax+1;
IslemAdimSayisi1=IslemAdimSayisi;
IslemAdimSayisi1(:,1)=[]; % indrigenmis IslemAdimSayisi
KaplamaIslemAdimSayisi=IslemAdimSayisi1(2,4:IslemAdimiSayisiMax1-1);
for i=1:3 %Islem adimlarina ait basinc, sicakli ve aps değerlerini bulan döngü
%Reçetelerin ilk üç adımı hazırlık olduğu için diğerlerinden ayrılıyor
SatirMax=SatirMin+IslemAdimSayisi1(2,i)-1;
if i==1 %islem adimi 1 icin basinc degeri bulunuyor
BasincDegerleri=KontrolVeri(SatirMin:SatirMax,14); %excel dosyasından satır aralığı çekilip INITIALminBasinc dizisine atandı
MinBasincDizisi(i)=min(BasincDegerleri);
MinSicaklikDizisi(i)="#N/A'";
MaxSicaklikDizisi(i)="#N/A'";
RateAverageDizisi(i)="#N/A'";
Aps1CoilCurrentMaxDizisi(i)="#N/A'";
Aps1CoilCurrentAverageDizisi(i)="#N/A'";
Gas1MinDizisi(i)="#N/A'";
Gas1MaxDizisi(i)="#N/A'";
Gas2MinDizisi(i)="#N/A'";
Gas2MaxDizisi(i)="#N/A'";
KalinlikDizisi(i)="#N/A'";
SatirMin=SatirMax+1;
elseif i==2 %islem adimi 1 icin basinc degeri bulunuyor
BasincDegerleri=KontrolVeri(SatirMin:SatirMax,14);
MinBasincDizisi(i)=min(BasincDegerleri);
SicaklikDegerleri=KontrolVeri(SatirMin:SatirMax,134);
MinSicaklikDizisi(i)=min(SicaklikDegerleri); % k indisi burada 3 olduğu için -2 yapılarak MinSicaklikDizisi'nin ilk hanesine atandı
MaxSicaklikDizisi(i)=max(SicaklikDegerleri); % k indisi burada 3 olduğu için -2 yapılarak MaxSicaklikDizisi'nin ilk hanesine atandı
RateAverageDizisi(i)="#N/A'";
Aps1CoilCurrentMaxDizisi(i)="#N/A'";
Aps1CoilCurrentAverageDizisi(i)="#N/A'";
Gas1MinDizisi(i)="#N/A'";
Gas1MaxDizisi(i)="#N/A'";
Gas2MinDizisi(i)="#N/A'";
Gas2MaxDizisi(i)="#N/A'";
KalinlikDizisi(i)="#N/A'";
SatirMin=SatirMax+1;
else i=3;
BasincDegerleri=KontrolVeri(SatirMin:SatirMax,14);
MinBasincDizisi(i)=min(BasincDegerleri);
SicaklikDegerleri=KontrolVeri(SatirMin:SatirMax,134);
MinSicaklikDizisi(i)=min(SicaklikDegerleri);
MaxSicaklikDizisi(i)=max(SicaklikDegerleri);
Aps1AkimDegerleri=KontrolVeri(SatirMin:SatirMax,216);
Aps1CoilCurrentMaxDizisi(i)=max(Aps1AkimDegerleri);
Aps1CoilCurrentAverageDizisi(i)=mean(Aps1AkimDegerleri);
Gaz1MinDegerleri=KontrolVeri(SatirMin:SatirMax,226);
Aps1Gas1Degerleri=KontrolVeri(SatirMin:SatirMax,219);
Gas1MinDizisi(i)=min(Aps1Gas1Degerleri);
Gas1MaxDizisi(i)=max(Aps1Gas1Degerleri);
Aps1Gas2Degerleri=KontrolVeri(SatirMin:SatirMax,220);
Gas2MinDizisi(i)=min(Aps1Gas2Degerleri);
Gas2MaxDizisi(i)=max(Aps1Gas2Degerleri);
RateAverageDizisi(i)="#N/A'";
KalinlikDizisi(i)="#N/A'";
SatirMin=SatirMax+1;
end
end
for i=4:IslemAdimiSayisiMax1-1 % Son i?lem ad?m? sonland?rma oldu?u için herhangi bir shutter tkisi yok. Bu nedenle bu döngüden ç?kar?larak en altta ayr?ca ele al?nd?.
if i==4
SatirMax=SatirMin+IslemAdimSayisi1(2,i)-1; % yukar?daki döngü i=3 olarak tamamland?. Dördüncü veriyi almak için i+1 kullan?ld?
% Shutter Matrisini olu?turmak
%ShutterMatrisi=[SatirMax-SatirMin,1];
for j=1:10 % 10 shutter say?s?
ShutterMatrisi(:,j)=KontrolVeri(SatirMin:SatirMax,ShutterDizisi(j)); %Shutterlar?n ana data içinde bulunduklar? sütun say?lar?n? tutan dizi
end
%shutter matrisinde 1'in hangi sütunda ve satırlarda olduğunu bulan
%döngü
for sutun=1:10
for satir=1:IslemAdimSayisi1(2,i)
if ShutterMatrisi(satir,sutun)==1
BirSatirSayisi=satir;
BirSutun=sutun;
end
end
end
%1'lerin oldugu sutunda kaç tane 1 olduğunu bulan döngü
SifirAdet=0;
for k=1:satir
if ShutterMatrisi(k,BirSutun)==0
SifirAdet=SifirAdet+1;
else ShutterMatrisi(k,BirSutun)=1; %Bu yazıl hatalı mı
adet=SifirAdet;
break;
end
end
BirBaslangic=SifirAdet+1;
BirBitis=BirSatirSayisi;
ShutterAc=SatirMin+BirBaslangic;
ShutterKapa=SatirMin+BirBitis;
BasincDegerleri=KontrolVeri(ShutterAc:ShutterKapa,14);
MinBasincDizisi(i)=min(BasincDegerleri);
SicaklikDegerleri=KontrolVeri(ShutterAc:ShutterKapa,134);
MinSicaklikDizisi(i)=min(SicaklikDegerleri);
MaxSicaklikDizisi(i)=max(SicaklikDegerleri);
Aps1AkimDegerleri=KontrolVeri(ShutterAc:ShutterKapa,216);
Aps1CoilCurrentMaxDizisi(i)=max(Aps1AkimDegerleri);
Aps1CoilCurrentAverageDizisi(i)=mean(Aps1AkimDegerleri);
Aps1Gas1Degerleri=KontrolVeri(SatirMin:SatirMax,219);
Gas1MinDizisi(i)=min(Aps1Gas1Degerleri);
Gas1MaxDizisi(i)=max(Aps1Gas1Degerleri);
Aps1Gas2Degerleri=KontrolVeri(SatirMin:SatirMax,220);
Gas2MinDizisi(i)=min(Aps1Gas2Degerleri);
Gas2MaxDizisi(i)=max(Aps1Gas2Degerleri);
RateAverageDizisi(i)="#N/A'";
KalinlikDizisi(i)="#N/A'";
SatirMin=SatirMax+1;
else i~=4;
SatirMax=SatirMin+IslemAdimSayisi1(2,i)-1;
kap=kap+1;
if KaplamaIslemAdimSayisi(1,kap)<KaplamaIslemAdimSayisi(1,kap+1)
ShutterMatrisi(IslemAdimSayisi1(2,i-1)+1:IslemAdimSayisi1(2,i),1)=0;
else KaplamaIslemAdimSayisi(1,kap)>KaplamaIslemAdimSayisi(1,kap+1);
ShutterMatrisi(KaplamaIslemAdimSayisi(kap+1)+1:KaplamaIslemAdimSayisi(kap),:)=[];
end
% Shutter Matrisini olu?turmak
for j=1:10 % 10 shutter say?s?
ShutterMatrisi(:,j)=KontrolVeri(SatirMin:SatirMax,ShutterDizisi(j)); %Shutterlar?n ana data içinde bulunduklar? sütun say?lar?n? tutan dizi
end
for sutun=1:10
for satir=1:IslemAdimSayisi1(2,i)
if ShutterMatrisi(satir,sutun)==1
BirSatirSayisi=satir;
BirSutun=sutun;
end
end
end
SifirAdet=0;
for k=1:satir
if ShutterMatrisi(k,BirSutun)==0
SifirAdet=SifirAdet+1;
else ShutterMatrisi(k,BirSutun)=1; %Bu yazıl hatalı mı
adet=SifirAdet;
break;
end
end
BirBaslangic=SifirAdet+1;
BirBitis=BirSatirSayisi;
ShutterAc=SatirMin+BirBaslangic;
ShutterKapa=SatirMin+BirBitis;
BasincDegerleri=KontrolVeri(ShutterAc:ShutterKapa,14);
MinBasincDizisi(i)=min(BasincDegerleri);
SicaklikDegerleri=KontrolVeri(ShutterAc:ShutterKapa,134);
MinSicaklikDizisi(i)=min(SicaklikDegerleri);
MaxSicaklikDizisi(i)=max(SicaklikDegerleri);
Aps1CoilCurrentMaxDizisi(i)="#N/A'";
Aps1CoilCurrentAverageDizisi(i)="#N/A'";
Gas1MinDizisi(i)="#N/A'";
Gas1MaxDizisi(i)="#N/A'";
Gas2MinDizisi(i)="#N/A'";
Gas2MaxDizisi(i)="#N/A'";
RateDegerleri=KontrolVeri(ShutterAc:ShutterKapa,41);
RateAverageDizisi(i)=mean(RateDegerleri);
KalinlikDegerleri=KontrolVeri(ShutterAc:ShutterKapa,40);
KalinlikDizisi(i)=max(KalinlikDegerleri);
SatirMin=SatirMax+1;
end
end
i=IslemAdimiSayisiMax1;
SatirMax=SatirMin+IslemAdimSayisi1(2,i)-2;
BasincDegerleri=KontrolVeri(SatirMin:SatirMax,14); %excel dosyasından satır aralığı çekilip INITIALminBasinc dizisine atandı
MinBasincDizisi(i)=min(BasincDegerleri);
MinSicaklikDizisi(i)="#N/A";
MaxSicaklikDizisi(i)="#N/A";
RateAverageDizisi(i)="#N/A";
Aps1CoilCurrentMaxDizisi(i)="#N/A";
Aps1CoilCurrentAverageDizisi(i)="#N/A";
Gas1MinDizisi(i)="#N/A";
Gas1MaxDizisi(i)="#N/A";
Gas2MinDizisi(i)="#N/A";
Gas2MaxDizisi(i)="#N/A";
KalinlikDizisi(i)="''a''";
format shortEng
DataMatris(1,:)=MinBasincDizisi;
format shortG
DataMatris(2,:)=MinSicaklikDizisi;
DataMatris(3,:)=MaxSicaklikDizisi;
DataMatris(4,:)=RateAverageDizisi;
DataMatris(5,:)=Aps1CoilCurrentMaxDizisi;
DataMatris(6,:)=Aps1CoilCurrentAverageDizisi;
DataMatris(7,:)=Gas1MinDizisi;
DataMatris(8,:)=Gas1MaxDizisi;
DataMatris(9,:)=Gas2MaxDizisi;
DataMatris(10,:)=Gas2MaxDizisi;
DataMatris(11,:)=KalinlikDizisi;
DataMatris();
load DosyaAdi;
%xlswrite('''%c''.xlsx',DosyaAdi,DataMatris);
[filename, pathname] = uiputfile('.xlsx',DosyaAdi,'Choose a file name');
outname = fullfile(pathname, filename);
xlswrite(outname, DataMatris);
elseif PVD==0 && CVD==1
disp('Abovv');
else PVD==0 && CVD==0;
disp('Kaplama tipini seçin.');
end
That's my code. It get an excel tablo which is 17000x236. The first button gets the data and the second one makes calculations. When i push the second button it opens 5 more gui screen.
Image Analyst
Image Analyst on 1 Mar 2020
Attach the m-file and .fig file with the paper clip icon so we can actually run it ourselves.

Sign in to comment.

Accepted Answer

Thiago Henrique Gomes Lobato
When you do
save CVD
save PVD
...
you're actually saving your whole workspace, and thus later when you load it, you, at the same time, load many other GUI's and that's why you see other instances of the interface. You have here two options, either save only the variable, like:
save('CVD.mat','CVD')
Or, better, you use one of the standard methods to transfer data inside a GUI, as for example the handles structure (in this page there's a little tutorial http://matlab.izmiran.ru/help/techdoc/creating_guis/ch_program22.html). Basically you save all your variables in a structure called handles:
function callback1...
handles.CVD = 1; % Save variable in handles
guidata(hObject,handles); % tell the GUI to "update" the handles variable so other callback can see it
end
function callback2...
CVD = handles.CVD; % if you do first callback1 handles.CVD will now be 1
end
  3 Comments
Thiago Henrique Gomes Lobato
For matlab there's absolutely no difference between KontrolVeri and CVD in respect to save the variable/pass to the structure, so when you write
save KontrolVeri
you still save the interface within. In your code there's also no variable named 'ShutterDizi', only ShutterDizisi, which is defined at the VeriSec_Callback and will not be calleble in any other callback of your interface unless you save it somehow, as for example with the handles approach.
Onur ALPAY
Onur ALPAY on 4 Mar 2020
Hi,
I made a typing mistake about 'ShutterDizisi'. I understand what you mean and have solved the problem. Now I have only one interface.
Thank you so much for your help.

Sign in to comment.

More Answers (1)

Onur ALPAY
Onur ALPAY on 1 Mar 2020
Edited: Onur ALPAY on 1 Mar 2020
Hi,
You can see the attachments. I also attach the excel file you will need to take.
Here are the step.
1- Chose PVD
2- Chose "ZnSe_Koruma" from drop down menu.
3- Push "Veri Seç" button and wait for loading bar.
4- Push "Hesapla" button. After this step program opens 5 or 6 more interface.
These are enough for program, other menus are not using now.

Categories

Find more on App Building 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!