0
votes

I am trying to write a matlab gui code that will load data from CSV file and plot graph. And every time, I will load data by clicking the load data button, the plot should refresh and plot the new data. I was able to load data and plot first graph. However, If I click on the load data button second time and it loads data from different CSV file but it plots on the top of the first graph. I do not know how to refresh that graph every I load data and save it in a file new gui file . Please help me out. This is the first time I am working with Gui interface. I am posting my Load data callback function below. and Gui interface as .jpg attachment. Thank you.

    function shiva_Callback(hObject, eventdata, handles)
        hold off
    % load data
       %plot     
        yyaxis left
        loglog(t,a,'b')
        hold on
        loglog(t,t,'r')
        loglog(t,d,'c') 
        loglog(t,,'m')
        ylabel('% Text')
        xlabel('T')
        yyaxis right
        loglog(t,s,'y')
        loglog(t,st,'g')

        function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
1

1 Answers

2
votes

You have hold set to on which means that all new plots placed on the axes will be added to the existing plots rather than replacing them. The easiest change that you can make is to call hold off after you load the new data but before you start plotting (i.e. at the top of your callback).

function shiva_Callback(hObject, eventdata, handles)
    % Ensure that our new plots overwrite existing plots
    yyaxis left
    hold off

    yyaxis right
    hold off

    handles.filename = uigetfile('*.xls');

    % Load data in

    % Now plot the new plots
    yyaxis left
    loglog(p, r, 'b');

    % Enable adding plots again
    hold on

    loglog(p, t, 'r');

    % Plot the rest of your stuff

    yyaxis right
    loglog(p, a, 'y')
    hold on
    loglog(p, h, 'g')
    ylabel('State and Status');
    grid on