how can I save edited uitable?

169 Views Asked by At

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?

1

There are 1 best solutions below

0
Eve2020 On

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