How do you access the string of an edit box from one gui, in a callback associated with another gui?

In my GUI once I click the button "start" an "m-file" is loaded up (FVBExample2) which takes the information I have entered into my GUI to run tests on a camera. One of the tests is named "KineticSeries" and to tidy things up a bit, the parameters associated with this are entered into a separate GUI which launches when I click the button "Kinetic Series Settings".
I receive this error when I try to run my program...
Reference to non-existent field 'editboxkinserlen'.
Error in FVBExample2 (line 169)
KinSeriesLength=str2num(get(handles.editboxkinserlen,'String'));
Error in CamTestGUIbackupbeforeimage>previmage_Callback (line 1572)
FVBExample2
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in CamTestGUIbackupbeforeimage (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)CamTestGUIbackupbeforeimage('previmage_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
This edit box is located in the second GUI, is there something I should have in front of my code to tell Matlab to look for this box within the second GUI?
Thanks

 Akzeptierte Antwort

Jonathan - there are a couple ways of doing this. See Sharing between multiple GUIs or how to pass data between guis for examples on how to do this.
In the second link, if the HandleVisibility property for both GUIs are set to on, then you can use findobj function to find the other GUI using its tag. So, in your second GUI (or even from the Command Window), you may look for the first GUI as
hGui = findobj('Type','figure','Tag','GUI1');
where 'GUI1' is the value of the Tag property of the first GUI (typically, the default is figure1).
Then
if ~isempty(hGui)
% GUI has been found
% get widget handles for this GUI
handlesGui1 = guidata(hGui);
% now read the data from that GUI widgets
KinSeriesLength=str2num(get(handlesGui1.editboxkinserlen,'String'));
% etc.
end
Try the above and see what happens!

10 Kommentare

Thanks Geoff that sorted me out! Any idea why I don't get an image after running this code? the frame time and standard deviation come back as "0".
hGui = findobj('Type','figure','Tag','Gui2');
if ~isempty(hGui)
% GUI has been found
% get widget handles for this GUI
handlesGui2 = guidata(hGui);
% now read the data from that GUI widgets
KinSeriesLength=str2num(get(handlesGui2.editboxkinserlen,'String'))
AccumCycleTime=str2num(get(handlesGui2.editboxacummcyctime,'String'))
KinCycleTime=str2num(get(handlesGui2.editboxkincycletime,'String'))
Wide=str2num(get(handlesGui2.editboxkinserwidth,'String'))
High=str2num(get(handlesGui2.editboxkinserheight,'String'))
DisplayImage=(get(handlesGui2.kinserdisplayimage,'Value'))
% etc.
end
if acqvalue==3;
[ FrameMean, FrameStdDev ] = KineticSeries( KinSeriesLength, AccumCycleTime, KinCycleTime, Wide, High, DisplayImage )
That function contains this code:
function [ FrameMean, FrameStdDev ] = KineticSeries( KinSeriesLength, AccumCycleTime, KinCycleTime, Wide, High, DisplayImage )
%Runs a Kinetic Series and returns mean and Standard deviation
% Detailed explanation goes here
[ret]=SetAccumulationCycleTime(AccumCycleTime);
[ret]=SetKineticCycleTime(KinCycleTime);
[ret]=SetNumberKinetics(KinSeriesLength);
[ret] = PrepareAcquisition();
ImageArray = zeros(Wide, High); % Creates array of zeros Xpixels * Ypixels
ret=StartAcquisition; % Starts acquisition
ret=WaitForAcquisition; % Waits until Acquisition event occurs
for ImageCount = 1 : KinSeriesLength
[ret,ImageArray]=GetOldestImage(Wide * High); % Updates data in array with most recently acquired image (16-bit)
Image = reshape(ImageArray, Wide, High); % Returns xpixels by ypixels array whose
ImageStore(:,:,ImageCount)=Image;
ImageCount=ImageCount+1;
if DisplayImage==1
h=imagesc(Image); % Returns the handle for an image graphics object
set(h,'CData',Image); % Set Handle Graphics object properties
axis xy;
%set(gca,'YDir','reverse');
colormap(gray);
colorbar;
drawnow;
end
end
for ImageCount = 1 : KinSeriesLength
FrameMean(ImageCount)=mean(mean(ImageStore(:,:,ImageCount)));
SingleFrame(:,:,ImageCount)=double(ImageStore(:,:,ImageCount));
FrameStdDev(ImageCount)=std(SingleFrame(:));
end
end
But the video readout on my GUI just goes grey...
Jonathan - I don't know what your frame time is: AccumCycleTime, KinCycleTime, or something else? What happens when you put a breakpoint at the first line in the KineticSeries function? When it gets called, do you see reasonable input values (i.e. those as read from the other GUI).
And when you call
h=imagesc(Image);
where is the image being displayed? Can you not specify the axes of where it should be shown i.e. as
h=imagesc(Image,'Parent',myAxesHandle);
Also, is the line
set(h,'CData',Image);
necessary, since CData should already be Image given the previous line
h=imagesc(Image);
As for your image all being grey, it almost (?) seems to match the zero value on the colorbar. Could it be that Image is a matrix of all zeros? In fact, if I do the following
I = zeros(400,300);
h=imagesc(I);
colormap(gray)
colorbar
then my figure looks identical to your video readout. So what does GetOldestImage do (how does it use the input product of the width with height), and what is the value of ret? I think that this function is returning ImageArray arrays of all zeros.
Sorry, I was meant to say "frame mean". the tag of this axes is "axes1" but when I change the code to :
h=imagesc(Image,'Parent',axes1)
this error occurs...
Error in KineticSeries (line 27)
h=imagesc(Image,'Parent',axes1);
% Returns the handle for an image graphics
object
I suppose you could be right, If I remember correctly the value for frame mean and FrameStdDev came back as "0", so maybe this graph is just showing this? the ret function just returns a code to indicate one of these outcomes... I've received the drv_success even without an image showing(maybe just like you said, an image of an array of "0"s) and drv_p2invalid.
DRV_SUCCESS: Image has been copied into array.
DRV_NOT_INITIALIZED: System not initialized.
DRV_ERROR_ACK: Unable to communicate with card.
DRV_P1INVALID: Invalid pointer (i.e. NULL).
DRV_P2INVALID: Array size is incorrect.
DRV_NO_NEW_DATA: There is no new data yet.
This is the description in the function reference folder I have at work for this function.
[ret, arr] = GetOldestImage(size)
Description This function will update the data array with the oldest image in the circular buffer. Once the oldest image has been retrieved it no longer is available. The data are returned as long integers (32-bit signed integers). The "array" must be exactly the same size as the full image. Inputs size: total number of pixels. Outputs ret: Function return code
Sorry missed some of that, I will put a breakpoint in and see what happens... The input values come back valid as far as I can tell from the other GUI
If you use the code
h=imagesc(Image,'Parent',axes1)
is axes1 a field of the handles struct or just a local variable? It may not matter since I still think that the images are coming back as all zeros (for some reason..).
axes1 is the tag of my axes that I display the image on, im not too sure what you mean by local variable?
Is it a local variable in your function? You mentioned that you were getting an error, so I wasn't sure what that meant. But if you want to access that axes, whose tag is axes1, it is typically through the handles structure which manages all GUI widgets/control handles (and user-defined data). Just writing
h=imagesc(Image,'Parent',axes1)
may fail if axes1 is not a local variable within your function. Else, you would have to use
h=imagesc(Image,'Parent',handles.axes1)
assuming handles has been passed into your KineticSeries function. Which it hasn't, and neither has axes1. So both would generate the undefined variable of function error.
Oh, thanks Geoff. I don't think it is a local function, as I just made the axes on a GUI and this function was created by someone before that. So would I pass its handle into this function in the same way I took information from my second gui?
Yes, just add an extra parameter to your KineticSeries function.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by