Importing CSV values and using in different functions App Designer

Hello! I want to import a CSV file and format its values to use in multiple functions on App Designer. I want the values I extract from the CSV to be available globally. Since the file is massive (around 2 million rows and 50 columns), I was using datastore but I get multiple errors.
What I have tried so far:
  1. I created an external matlab file (.m) and tried to import that as a property but failed since it was not a (.mat) file.
  2. I have tried to code the importing and data formatting in a public property block in the App Designer but that does not recognize ds.
Any suggestion?

3 Comments

"external matlab file (.m) and tried to import that..."
If this is a static file as sounds as is, why not just create the .mat file and have the app load it into global app variable?
If it isn't static, same idea, just have a File menu that lets user select the file, and read it in.
2E6*50/1024/1024 --> 95 MB. That's not all that big these days of GB memory.
It is actually a 800,00KB file and can not be loaded into the program without using datastore.
I understand about using the File menu but what I do not understand is where I should place the code that reads and formats the file so that the variables (of the table / array) are accessible throughout the code.
I placed it inside the the Public Property but I get errors that say
The current use of 'ds' is inconsistent with its previous use or definition
ds = datastore("filename.csv")
ds.VariableNames(:,1) = {'time'};
AND
The current use of 'baseline' is inconsistent with its previous use or definition
baseline = readtable("filename.csv");
baseline(:,2)= [];
but this code works exactly fine in a normal matlab .m file!
You'll need to create the datastore object as a public property -- I would guess that should be in the startup code. It would be something more like
function initializeData(app)
app.ds = datastore("filename.csv");
...
where this function is called (or the code can be inline if it's not too complex) in the startup code and the ds variable is defined in the public section.
Then, you reference that global everywhere.
Same idea for the reading -- you pass the datastore handle to the function that does the read when it needs it. This way there's only one instance and it's global.
Would need to see more of the overall organization to write/place specifically, but that's the general idea.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2020b

Asked:

R
R
on 2 Jun 2022

Commented:

dpb
on 3 Jun 2022

Community Treasure Hunt

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

Start Hunting!