Using App Designer, saving (and loading) data from the Edit Fields of the GUI to a file?
    19 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have several numeric edit fields in my gui. How do I go about saving the entered data to a text file?  

I want to be able to save the entered values for the above Center Freq and Bandwidths to a file so I can recall them at a later time. Those fields are app.NumericEditField_CenterFreq1, app.NumericEditField_Bandwidth1, app.NumericEditField_CenterFreq2, etc. 
I have save and load buttons, and understand I need to place code in the call backs of those buttons, but I haven't been able to find any good examples.  I tried the below, but it saves it to a .mat file, which is unreadable in a text error. Is there an easier way to save and then load the data to and from my edit fields?
        function SaveButtonPushed(app, event)
            props = properties(app);
            lp    = length(props);
            values   = cell(1,lp);
            visibilities   = cell(1,lp);
            for i = 1:lp
                propName = props{1};
                property = app.(propName);
                if isprop(property, 'Value')
                    values{i} = app.(propName).Value;
                end
            end          
            file = uiputfile('*.mat', "Save Message" );
            if file
                save(file, 'props', 'values', 'visibilities');
            end
The above saves data, but not sure if it is correct since it is unreadable.  When I try and load, I dont get anything in the edit fields:
        function LoadButtonPushed(app, event)
            [file,path] = uigetfile('*.mat');
            selectedfile = fullfile(file);
            data=load(selectedfile);
        end
Thanks in advance!
0 件のコメント
採用された回答
  Rik
      
      
 2023 年 4 月 23 日
        Your loading function needs to load the file, and then set the values of the fields. It currently only does the former.
A mat file is not a text file. You can examine the contents with Matlab (or even Octave), but not with text readers. If you want a text file, you may consider converting to JSON.
15 件のコメント
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で JSON Format についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


