フィルターのクリア

How to make an app that does not loose data when it's closed?

3 ビュー (過去 30 日間)
piston_pim_offset
piston_pim_offset 2023 年 11 月 22 日
コメント済み: dpb 2023 年 11 月 30 日
I have an app kind of a calculator. It stores data in a UITable with a special property that increases with each pressing on the button to store the data in the app. UITable and its variable are reset when the app restarted. Is there a way to prevent the them to get reset and continue from the previous work?

採用された回答

dpb
dpb 2023 年 11 月 24 日
編集済み: dpb 2023 年 11 月 24 日
Do you want/need the UITable to contain the previous data, too? Or just add onto the saved data what is new in the user table each time?
Since you're using a table component anyway, it would be simplest to use writetable and its companion; there's a named parameter-value pair 'WriteMode' with the value 'Append' for precisely the purpose of adding to the existing data.
If you want the table repopulated first, then read the file and put into the table; you'll then need to keep a pointer to how much was already there (or, if the user can change something before, then just rewrite the whole file). If not, but starting with a new, clean user interface, you're essentially done.
  3 件のコメント
piston_pim_offset
piston_pim_offset 2023 年 11 月 27 日
Now app can save the data without overwriting.
But there is another problem:
Can we rewrite a row of the data if one element is the same in a row?
dpb
dpb 2023 年 11 月 30 日
Need more complete description of the problem; if the table is user-editable and the user changes an existing line, it will be rewritten as changed. If you are continuing to populate the table with the complete content as you first described, then simply read/writing the whole table every time is by far the simplest expedient.
If you're not repopulating the user table, but adding new content and appending, then it would take background work to read the file portion and compare to the new data to find any duplicate entries.
We simply don't have a sufficient description of how your app works to be able to know what it is you're trying to do...

サインインしてコメントする。

その他の回答 (1 件)

Angelo Yeo
Angelo Yeo 2023 年 11 月 24 日
I understand you do not want to overwrite previous files and want to make new name everytime. I suggest you save data with time marker of present time. For example,
filename = "myfile_"+string(datetime('now', 'format', 'yyyyMMddHHmmss'))+".mat";
save(filename, 'mydata')
When you come back, you can use the latest data among the "mat" based on the filenames.
  3 件のコメント
piston_pim_offset
piston_pim_offset 2023 年 11 月 24 日
編集済み: piston_pim_offset 2023 年 11 月 24 日
Can we save all data in a single file (excel if probable) @Angelo Yeo? I tried ".xlsx" extension for excel, but it gave an error. And l also tried to fit all the data in a single file by using a cell array as a private property, again an error line appeared saying "variable could'nt found" or something like that.
Angelo Yeo
Angelo Yeo 2023 年 11 月 24 日
If you only specify the filename, all variables in base workspace will be saved as "mat".
If you want to save files as xlsx, try to use writetable.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by