Info
This question is closed. Reopen it to edit or answer.
Two axes GUI plot when i run it for the third time...
3 views (last 30 days)
Show older comments
Hi,
Got a problem with GUIDE. I created two GUI, one with two pushbuttons, first one to choose data, second to transfer data to an another GUI and open it. This second GUI is about to plot 2 contours of the data on two differents axes.
So in the first GUI i'm using xlsread to pick up data on excel and it works so i got finally 6 variables T2,V2,N2 ( for the first plot ) and T3,V3,N3 ( for the second plot ). I use global variable to transfer these variable to my puschbutton that call my second GUI ans it works too.
Then the second GUI openning and got error on the first plot and no plot display. Then I click another time on my puschbutton and it opended again but only with the first plot created and got error too but on the second plot. Then I click again on the button and finally, after 3 times, the two plots are display.
If someone know why...
Here is the puschbutton callback to pick up the data : ( just asking the user to choose the excel then type the differents cellrange )
global T2;
global V2;
global N2;
global T3;
global V3;
global N3;
startingFolder = 'C:\Users\moi\Documents\ISAT\4A\Stage FPT\Programme\';
if ~exist(startingFolder, 'dir')
startingFolder = pwd;
end
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
return;
end
fullExcelFileName2 = fullfile(folder, baseFileName);
defaultValue = 'Sheet1';
titleBar = 'Entrer le nom de la feuille 1';
userPrompt = 'Entrer le nom de la feuille 1';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end;
sheetName2 = strtrim(char(caUserInput));
defaultValueT = '';
titleBarT = 'Entrer les cellules T1';
userPromptT = 'Entrer les cellules T1';
caUserInputT = inputdlg(userPromptT, titleBarT, 1, {num2str(defaultValueT)});
if isempty(caUserInputT),return,end;
cellsRangeT2 = strtrim(char(caUserInputT));
defaultValueV = '';
titleBarV = 'Entrer les cellules V1';
userPromptV = 'Entrer les cellules V1';
caUserInputV = inputdlg(userPromptV, titleBarV, 1, {num2str(defaultValueV)});
if isempty(caUserInputV),return,end;
cellsRangeV2 = strtrim(char(caUserInputV));
defaultValueN = '';
titleBarN = 'Entrer les cellules N1';
userPromptN = 'Entrer les cellules N1';
caUserInputN = inputdlg(userPromptN, titleBarN, 1, {num2str(defaultValueN)});
if isempty(caUserInputN),return,end;
cellsRangeN2 = strtrim(char(caUserInputN));
T2 = xlsread(fullExcelFileName2, sheetName2, cellsRangeT2);
V2 = xlsread(fullExcelFileName2, sheetName2, cellsRangeV2);
N2 = xlsread(fullExcelFileName2, sheetName2, cellsRangeN2);
startingFolder = 'C:\Users\moi\Documents\ISAT\4A\Stage FPT\Programme\';
if ~exist(startingFolder, 'dir')
startingFolder = pwd;
end
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
return;
end
fullExcelFileName3 = fullfile(folder, baseFileName)
defaultValue = 'Sheet1';
titleBar = 'Entrer le nom de la feuille 2';
userPrompt = 'Entrer le nom de la feuille 2';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end;
sheetName3 = strtrim(char(caUserInput))
defaultValueT = '';
titleBarT = 'Entrer les cellules T2';
userPromptT = 'Entrer les cellules T2';
caUserInputT = inputdlg(userPromptT, titleBarT, 1, {num2str(defaultValueT)});
if isempty(caUserInputT),return,end;
cellsRangeT3 = strtrim(char(caUserInputT))
defaultValueV = '';
titleBarV = 'Entrer les cellules V2';
userPromptV = 'Entrer les cellules V2';
caUserInputV = inputdlg(userPromptV, titleBarV, 1, {num2str(defaultValueV)});
if isempty(caUserInputV),return,end;
cellsRangeV3 = strtrim(char(caUserInputV))
defaultValueN = '';
titleBarN = 'Entrer les cellules N2';
userPromptN = 'Entrer les cellules N2';
caUserInputN = inputdlg(userPromptN, titleBarN, 1, {num2str(defaultValueN)});
if isempty(caUserInputN),return,end;
cellsRangeN3 = strtrim(char(caUserInputN))
T3 = xlsread(fullExcelFileName3, sheetName3, cellsRangeT3);
V3 = xlsread(fullExcelFileName3, sheetName3, cellsRangeV3);
N3 = xlsread(fullExcelFileName3, sheetName3, cellsRangeN3);
Here is the callback for the puschbutton that call my second GUI...
handles = guidata(hObject);
guidata(hObject, handles);
global T2;
global V2;
global N2;
global T3;
global V3;
global N3;
compare(handles)
hf=findobj('Name','pageprincipale');
close(hf);
And here is the lines for the function that display the two plot of the second GUI...
function compare_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles=guidata(hObject);
axes(handles.axes1)
global T2;
global V2;
global N2;
global rangeY2;
global rangeX2;
global Z2;
global X2;
global Y2;
rangeY2=min(T2):55:max(T2);
rangeX2=min(V2):55:max(V2);
Z2 = griddata(V2,T2,N2,X2,Y2,'cubic');
[X2,Y2]=meshgrid(rangeX2,rangeY2);
rangeZ2=floor(min(N2)):0.1:ceil(max(N2));
contour(X2,Y2,Z2,[0 0.1 0.2 0.3 0.4 0.5 1 2 3 4 5 6 7 8 9],'showtext','on');
set(gca,'xlim',[800 2400],'xtick',800:100:2400);
set(gca,'ylim',[0 2500],'ytick',0:200:2500);
axes(handles.axes2)
global T3;
global V3;
global N3;
global rangeY3;
global rangeX3;
global Z3;
global X3;
global Y3;
rangeY3=min(T3):55:max(T3);
rangeX3=min(V3):55:max(V3);
Z3 = griddata(V3,T3,N3,X3,Y3,'cubic');
[X3,Y3]=meshgrid(rangeX3,rangeY3);
rangeZ3=floor(min(N3)):0.1:ceil(max(N3));
contour(X3,Y3,Z3,[0 0.1 0.2 0.3 0.4 0.5 1 2 3 4 5 6 7 8 9],'showtext','on');
set(gca,'xlim',[800 2400],'xtick',800:100:2400);
set(gca,'ylim',[0 2500],'ytick',0:200:2500);
guidata(hObject, handles);
And finaly the error I got when I push the button for the first time ( the second time is the same but replace the "2" by "3" ...
Error using contour (line 55)
Lengths of X and Y must match number of cols and rows in Z, respectively.
Error in compare_compare_OpeningFcn (line 43)
contour(X2,Y2,Z2,[0 0.1 0.2 0.3 0.4 0.5 1 2 3 4 5 6 7 8 9],'showtext','on');
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in compare (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in pageprincipale>pushbutton4_Callback (line 204)
compare(handles)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in pageprincipale (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)pageprincipale('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
It's like that the first time it doesn't took the variable so error, the second time it take correctly the variables for the first plot but not for the second and the third time it take all variables for the two plots...
If someone could give a try to give me a solution to this problem it would be appreciate.
Thank's.
Baptiste
2 Comments
Adam
on 15 Nov 2018
What is this code attempting to do?
The first two lines do effectively nothing, then all the global variables (which are a disaster waiting to happen anyway) declared which also seem to do nothing, so the whole code boils down to just passing the handles of this GUI to your compare function.
handles = guidata(hObject);
guidata(hObject, handles);
global T2;
global V2;
global N2;
global T3;
global V3;
global N3;
compare(handles)
hf=findobj('Name','pageprincipale');
close(hf);
Answers (2)
Baptiste Tarbouriech
on 16 Nov 2018
Edited: Baptiste Tarbouriech
on 16 Nov 2018
1 Comment
Jan
on 16 Nov 2018
Please do not post parts of the question in the section for answers. See my answer, which is actually a comment to this message.
Jan
on 16 Nov 2018
Edited: Jan
on 16 Nov 2018
This seem to be trivial. After:
function test2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
T22 = [];
...
h = findobj('Tag','test1');
if ~isempty(h)
test1data = guidata(h);
if isfield(test1data,'T22')
T22 = test1data.T22;
end
end
axes(handles.axes1)
the field handles.T22 is not defined. If any object is found, which has the tag 'test1' (even in another GUI - is this really wanted?!), teh variable T22 is defined, but not handles.T22 . Then
rangeY2=min(handles.T22):55:max(handles.T22);
must fail with the show message.
Use the debugger to examine such problems:
dbstop if error
After typing this in the command window, Matlab stops when an error occurs. Then check the values of the variables. You will see that handles does not contain the expected field T22. handles.T22 is created inside the pushbutton1_Callback, but you request it in the OpeningFcn already, which is evaluated during the figure is created.
3 Comments
Jan
on 16 Nov 2018
If this line fails:
Z2 = griddata(V22,T22,N22,X2,Y2,'cubic');
set a breakpoint there and check the sizes of the used variables. I suggest another time to use the debugger by your own, because this is the right tool for finding out the reasons of errors.
This question is closed.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!