Trying to export an Array of data that's being calculated in a GUI

1 view (last 30 days)
I want to store data in an array in app designer, I am not sure how to store the data, I am having trouble using arrays.Is their any alternative methods to store and then export data in app designer
Text = fopen('document')
B = 2;
C = 5;
i = 1
when button pushed
for i > 20
A = read(Text)
App.Value1 = A + B;
App.Value2 = A + C;\
Graph(App.Value1, App.Value2);
Hold on
store(i) = [App.Value1 App.Value2]; %stores data in array
i = i + 1;
end
Export(store);

Answers (1)

Ravi
Ravi on 29 Sep 2023
Hi Seth,
If I understand your question correctly, your requirement is to input data from a text file in "AppDesigner", perform operations on the data, plot the data, store the data in an array, and finally write the array to a text file.
I hope the procedure below helps you solve the issue you are facing.
  1. Create the required variables in the properties section with public access.
  2. Create a function (can be a callback function that triggers when a button is clicked) that initializes your variables “A”, and “store” and performs the required operations and finally writes the data into an output file.
  3. Instead of explicitly mentioning hold on in the AppDesigner, it is suggested to pass the component name as an argument, since there can be many arguments present i.e., hold(app.UIAxes, "on")
  4. New entries can be added to the “store” array using concatenation rather than using index assignment, since there is no pre-allocation of memory to the “store” array.
Initializing “A” can be done using the "readmatrix" function. With this, the complete data that is present in the text file is stored as an array in “A” and the entries in it can be accessed using indexing. Instead of reading one line of text file at a time, whole data in the file is read into a single array. Similarly, for writing the output into a file, "writematrix" function can be used. Initialize “store” as an empty array.
Below mentioned are a few links that can help you understand more about reading and writing a matrix, using the hold function.
  • Reading a matrix from a file: - https://www.mathworks.com/help/matlab/ref/readmatrix.html
  • Writing a matrix to a file: - https://www.mathworks.com/help/matlab/ref/writematrix.html
  • Hold: - https://www.mathworks.com/help/matlab/ref/hold.html
Hope this helps.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!