I want to collect data to cell array in Matlab App Designer.
    8 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    piston_pim_offset
 el 28 de Oct. de 2023
  
    
    
    
    
    Comentada: Voss
      
      
 el 6 de Nov. de 2023
            Hi,
l am trying to make an app that takes some input from user and makes calculations, and then collects the data (in cell array or something). 
After that, input boxes should set to zero to allow user to input other cases. My goal is collecting all the data from user, and allow user to get the result for a sepecific case if wanted.
I couldn't make the collection part for more than 1 case.
Thank you in advance.
2 comentarios
  piston_pim_offset
 el 2 de Nov. de 2023
				
      Editada: piston_pim_offset
 el 2 de Nov. de 2023
  
			
		Respuesta aceptada
  Voss
      
      
 el 2 de Nov. de 2023
        Here is an app that collects data entered into two numeric editfields into matrix, and also performs some calculations and stores the results in a cell array.
To use: 
- Enter some numbers.
 - Hit the Save button to store the numbers, perform some calculations, store the results, and reset the editfields to 0.
 - Hit the Done button to save all the data and results collected so far into a mat file and close the application.
 
Hopefully you can get some ideas about what to do with your real app from this simple app.
2 comentarios
  Voss
      
      
 el 6 de Nov. de 2023
				classdef test < matlab.apps.AppBase
    % Properties that correspond to app components
    properties (Access = public)
        UIFigure             matlab.ui.Figure
        SaveButton           matlab.ui.control.Button
        Data2EditField       matlab.ui.control.NumericEditField
        Data2EditFieldLabel  matlab.ui.control.Label
        Data1EditField       matlab.ui.control.NumericEditField
        Data1EditFieldLabel  matlab.ui.control.Label
        DoneButton           matlab.ui.control.Button
    end
    properties (Access = private)
        data = [];
        results = {};
    end
    % Callbacks that handle component events
    methods (Access = private)
        % Button pushed function: SaveButton
        function cb_save(app, event)
            % store the EditFields' current values in a new row of app.data:
            data1 = app.Data1EditField.Value;
            data2 = app.Data2EditField.Value;
            app.data(end+1,:) = [data1 data2];
            % perform some calculations:
            result = {data1*data2, data1+data2, data1/data2};
            % store the result in a new element of app.results:
            app.results{end+1} = result;
            % reset the EditFields' values to 0:
            app.Data1EditField.Value = 0;
            app.Data2EditField.Value = 0;
        end
        % Button pushed function: DoneButton
        function cb_done(app, event)
            % save app.data and app.results to a mat file:
            data = app.data;       %#ok<ADPROPLC> 
            results = app.results; %#ok<ADPROPLC> 
            save('data_and_results.mat','data','results');
            % close the application:
            close(app.UIFigure);
        end
    end
    % Component initialization
    methods (Access = private)
        % Create UIFigure and components
        function createComponents(app)
            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 214 132];
            app.UIFigure.Name = 'MATLAB App';
            % Create DoneButton
            app.DoneButton = uibutton(app.UIFigure, 'push');
            app.DoneButton.ButtonPushedFcn = createCallbackFcn(app, @cb_done, true);
            app.DoneButton.Position = [121 15 70 22];
            app.DoneButton.Text = 'Done';
            % Create Data1EditFieldLabel
            app.Data1EditFieldLabel = uilabel(app.UIFigure);
            app.Data1EditFieldLabel.HorizontalAlignment = 'right';
            app.Data1EditFieldLabel.Position = [32 94 44 22];
            app.Data1EditFieldLabel.Text = 'Data 1:';
            % Create Data1EditField
            app.Data1EditField = uieditfield(app.UIFigure, 'numeric');
            app.Data1EditField.Position = [91 94 100 22];
            % Create Data2EditFieldLabel
            app.Data2EditFieldLabel = uilabel(app.UIFigure);
            app.Data2EditFieldLabel.HorizontalAlignment = 'right';
            app.Data2EditFieldLabel.Position = [32 57 44 22];
            app.Data2EditFieldLabel.Text = 'Data 2:';
            % Create Data2EditField
            app.Data2EditField = uieditfield(app.UIFigure, 'numeric');
            app.Data2EditField.Position = [91 57 100 22];
            % Create SaveButton
            app.SaveButton = uibutton(app.UIFigure, 'push');
            app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @cb_save, true);
            app.SaveButton.Position = [31 15 70 22];
            app.SaveButton.Text = 'Save';
            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end
    % App creation and deletion
    methods (Access = public)
        % Construct app
        function app = test
            % Create UIFigure and components
            createComponents(app)
            % Register the app with App Designer
            registerApp(app, app.UIFigure)
            if nargout == 0
                clear app
            end
        end
        % Code that executes before app deletion
        function delete(app)
            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end
Más respuestas (0)
Ver también
Categorías
				Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!