Hello!
I am currently making a GUI in which you graphically select data from one plot and use it to produce an image.
I have 5 different pushbuttons which essentially do the same thing: allow for selection of a plotting range using ginput, display image over the corresponding data range (using imagesc) and update two edit text fields with the values obtained from ginput. However, I want each button to plot to a different set of axes (i.e. 5 different axes), and update different edit text fields.
Pushbutton handles are pbhTW1 … pbhTW5, and they each have a 'Tag' of '1' … '5' for reference. Axes for plotting the images are ahTW1 … ahTW5. There are two edit text fields accompanying each image, handles ethTW1a, ethTW1b … ethTW5a, ethTW5b.
I am currently achieving this using the following callback function, which is executed when each pushbutton is pressed:
function TWOut = TWPlot(hObject,~) X=ginput(2); if X(1)<X(2), WinStart=floor(X(1)); WinStop=floor(X(2)); else WinStart=floor(X(2)); WinStop=floor(X(1)); end TWOut=zeros(PixX*PixY,1); h=waitbar(0, ['Plotting from channel ' num2str(WinStart) ... ' to channel ' num2str(WinStop) '...']); steps=WinStop-WinStart; for i=WinStart:WinStop, fseek(fid,20+(i-1)*4,'bof'); im=fread(fid,inf,'int32',(TCSPCChannels-1)*4); TWOut=TWOut+im; step=i-(WinStart-1); waitbar(step/steps) end close(h) TWOut=reshape(TWOut,PixY,PixX)'; clear im Ref = get(hObject, 'Tag'); if Ref == '1', set(fh,'CurrentAxes',ahTW1); imagesc(TWOut) set(ethTW1a,'String',num2str(WinStart)); set(ethTW1b,'String',num2str(WinStop)); TWOut1 = TWOut; elseif Ref == '2', set(fh,'CurrentAxes',ahTW2); imagesc(TWOut) set(ethTW2a, 'String', num2str(WinStart)); set(ethTW2b, 'String', num2str(WinStop)); TWOut2 = TWOut; elseif Ref == '3', set(fh,'CurrentAxes',ahTW3); imagesc(TWOut) set(ethTW3a, 'String', num2str(WinStart)); set(ethTW3b, 'String', num2str(WinStop)); TWOut3 = TWOut; elseif Ref == '4', set(fh,'CurrentAxes',ahTW4); imagesc(TWOut) set(ethTW4a, 'String', num2str(WinStart)); set(ethTW4b, 'String', num2str(WinStop)); TWOut4 = TWOut; elseif Ref == '5', set(fh,'CurrentAxes',ahTW5); imagesc(TWOut) set(ethTW5a, 'String', num2str(WinStart)); set(ethTW5b, 'String', num2str(WinStop)); TWOut5 = TWOut; end end
I would really like to tidy up all of the if statements at the end of the function. I was thinking that I could maybe use genvarname to have a condense these into a few lines, e.g.
Ref = get(hObject, 'Tag'); set(fh, 'CurrentAxes', genvarname(['ahTW' Ref])); imagesc(TWOut) set(genvarname(['ethTW' Ref 'a']), 'String', num2str(WinStart)); set(genvarname(['ethTW' Ref 'b']), 'String', num2str(WinStop)); genvarname(['TWOut' Ref]) = TWOut;
but from what I understand of genvarname this will not work as a variable name is not actually created using this function.
If anyone has any ideas on how I could achieve this, I would be really grateful . It's not the end of the world if it's not possible, as my current code does the job, but it would be a nice luxury and useful for future callback functions that I plan to use in my GUI.
Thank you very much!
Siân
Best Answer