Elizabeth asked . 2021-02-05

How to merge the waitbar into UIcontrol GUI

I have a UIcontrol program like below
 
 
 
function [] = MyGui()

S.fh = figure('units','pixels',...
              'position',[200 200 800 800],...
              'menubar','none',...
              'name','GUI_2',...
              'numbertitle','off',...
              'resize','off');

S.ls = uicontrol('Style','text',...
                 'String','INTERACTIVE PARAMETER UPDATE',...
                 'FontWeight','bold',...
                 'FontSize', 12,...
                 'position',[200 700,400,50]);          

S.pb1 = uicontrol('style','push',...
                 'units','pix',...
                 'position',[350 400 100 40],...
                 'fontsize',12,...
                 'string','Start',...
                 'callback',{@start_call});

S.ed = uicontrol('style','edit',...
                 'unit','pix',...
                 'position',[220 300 100 40],...
                 'fontsize',12,...
                 'string','New String');

S.pb2 = uicontrol('style','push',...
                 'units','pix',...
                 'position',[500 300 100 40],...
                 'fontsize',12,...
                 'string','Add String',...
                 'callback',{@update_call,S});

%Function for getting the nTs value and passing into encdec             
function [] = update_call(varargin)
% Callback for pushbutton, reads new string from edit box.
S = varargin{3};
addstr = str2double(get(S.ed,'string')); % The string to add to the stack.
if ~strcmp(addstr,'NaN') 
    if addstr > 0 && addstr < 100
    addstr
    %pass the value to encdec
else
    msgbox('Please enter a number between 1 and 100','WARNING')
    end
end

%Function for starting the main program
function [] = start_call(varargin)
MainProgram
I am doing following tasks 1. I press the start and "MainProgram" runs. (Its a long running process) 2. I put some value in edit text box and press the update 3. The value will be passed onto the "MainProgram" for update.
Now I have two questions 1. there is a waitbar in MainProgram and how to merge that in main GUI (Instead of having a seperate pop-up). (start_call) 2. If user enters "addstr" value and press update, how can I interrupt MainProgram to take this addstr value for further processing ?

matlab , signal , signal processing , gui

Expert Answer

John Michell answered . 2024-12-21 02:37:27

Statisticalbeginner - rather than using a slider to record your progress, consider using an axes object which you would then draw an image representing the progress completed. For example, your GUI may have an axes for  plotting something, a push button to kick-off the processing, and another axes to record progress. If you give your GUI a unique Tag (see the properties inspector for your GUI) and set its HandleVisibility property to on, then your main program can look for this GUI and update the axes that has been designated as the wait (or progress) bar.

 

 function updateWaitBar
        % find the GUI whose tag is GuiWaitBarExample (GUI HandleVisibility
        % property must be set to on)
        hGui = findobj('Tag','GuiWaitBarExample');
        if ~isempty(hGui)

            % get the GUI handles structure
            handles = guidata(hGui);

            % axes2 is the waitbar
            if ~isempty(handles) && isfield(handles,'axes2')

                % if the waitBarImg doesn't exist, then create it and the
                % image graphics object
                if ~isfield(handles,'waitBarImg')
                    handles.waitBarImg  = uint8(ones(1,maxIters,3)*255);
                    handles.hWaitBarImg = image(handles.waitBarImg,'Parent',handles.axes2);
                end

                % reset to a white background
                if k == 1
                    handles.waitBarImg(:,:,:) = 255;
                end

                % set the progress complete portion of the wait bar
                handles.waitBarImg(:,k,1) = 255;  % red
                handles.waitBarImg(:,k,2) = 0;    % green
                handles.waitBarImg(:,k,3) = 0;    % blue

                % update the "drawn" image graphic object with the new data
                set(handles.hWaitBarImg,'CData',handles.waitBarImg);

                % ensure that the axes and ticks are hidden
                bgClr = get(handles.GuiWaitBarExample, 'Color');
                set(handles.axes2,'XTick',[],'YTick',[],'XTickLabe',[],'YTickLabel',[],'XColor',bgClr,'YColor',bgClr);

                % save the updated handles structure
                guidata(hGui,handles);
            end
        end
    end
 end
Note that the above function is nested within the parent main program GuiWaitBarExampleProg and so has access to the k and maxIters defined there. Run the attached GUI, press the button, and see what happens!

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.