1

i have a Matlab program done with a real time plot that acquire data from a LDR sensor with arduino. Now i want to implement that program in a GUI and i'm facing some problems with ploting. Here is the part of my program that i dont know how to plot in GUI mode.

(...) While(1) state = a.analogRead(0); (...) axis tight drawnow; x = [x, state]; plot(x,'-*b'); grid on; end

The code must be in the OpeningFcn? Should i just copy paste the into there? What do i have to change in the ploting code? Thank you very much!

1 Answer 1

1

A neverending while loop in OpeningFcn will indefinitely lock up your GUI. You're better off creating a timer object and running your 'continually' plotting code code in its callback; an example:

function myui_OpeningFcn(hObject, eventdata, handles, varargin)

    % Create timer with delay of 0.1 seconds
    handles.tmrPlot = timer( ...
        'ExecutionMode', 'FixedRate', ...
        'Period', 0.1, ...
        'TimerFcn', @myPlottingFunction);

    % Store in ui data
    guidata(hObject, handles);

    % Start it!
    start(handles.tmrPlot);
end

function myPlottingFunction(src, evt)
    % Do some plotting
    plot(rand(10));

    drawnow;
end

With a timer you can also, for example, start and stop the execution in the callback of a button.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.