0

Within a function I've programmatically created an editable uitable with a plot. Whenever the cell values change, the plot updates. I'd like to set the new edited table as the output. My code so far:

function outputTable = begrenzung() 

t = table(Drehzahl, Drehmoment, 'RowNames',{'Startpunkt' 'P1' 'P2' 'P3' 'Endpunkt'}); 

fig = uifigure; 
fig.Position(3:4) = [822 360]; 

uit = uitable(fig,'ColumnEditable',true); 
uit.Data = t; 
uit.FontSize = 10; 
uit.FontWeight = 'bold'; 
uit.ColumnEditable = true; 
uit.Position(3) = 375; 
ax = uiaxes(fig); 
ax.Position(1) = 415; 
ax.YLabel.String = 'Drehmoment [Nm]'; 
ax.XLabel.String = 'Drehzahl [rpm]'; 
x = t{:,1}; 
y = t{:,2}; 
area(ax,x,y); 
ax.XLim = [0 45]; 
ax.YLim = [0 2000]; 
ax.Title.String = 'Feld der gefahrenen Punkte'; 
uit.CellEditCallback = @updatePlot; 

    function outputTable = updatePlot(src,event) 
    area(ax,uit.Data{:,1},uit.Data{:,2}); 
    end 

end 

How can I save the updated uitable after each value-change?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • What do you mean by "output" of callback? A callback is a set of commands that invoked whenever the user does something on the GUI. There is no program part that uses the callback products. If you want you can use it inside another program or callback, from the uitable handle, or save the table data to file inside the callback – Adiel Dec 12 '19 at 01:26
  • Where do you want to save the data? In a file? In a workspace variable? – Patrick Happel Dec 14 '19 at 18:22

1 Answers1

0

I have found a solution, even though this might not be the elegant way:

function [outputTable] = begrenzung() 

    t = table(Drehzahl, Drehmoment,...
        'RowNames',{'Startpunkt' 'P1' 'P2' 'P3' 'P4' 'Endpunkt'});

    fig = uifigure;    
    fig.Position(3:4) = [822 360]; 

    uit = uitable(fig);     
    uit.Data = t;    
    uit.FontSize = 10;   
    uit.FontWeight = 'bold'; 
    uit.ColumnEditable = true;   
    uit.Position(3) = 375;     
    ax = uiaxes(fig);     
    ax.Position(1) = 415;    
    ax.YLabel.String = 'Drehmoment [Nm]';    
    ax.XLabel.String = 'Drehzahl [rpm]';     
    x = t{:,1}; 
    y = t{:,2};     
    fill(ax,x,y,'c');   
    ax.XLim = [0 45]; 
    ax.YLim = [0 2000];     
    ax.Title.String = 'Feld der gefahrenen Punkte';     
    uit.CellEditCallback = @updatePlot;


        function [test] = updatePlot(src,event) 

            fill(ax,uit.Data{:,1},uit.Data{:,2},'c'); 
            outputTable = uit.Data; 

        end 

    outputTable = uit.Data;

    uiwait(fig);

end 

this way, my Output is the changed table