Save multiple datasets in different structures/properties in app designer
7 views (last 30 days)
Show older comments
Hello,
I am working on building an app in which I can analyze multiple datasets that have to be processed in a similar way.
The workflow will be to first load a particular dataset. Which dataset is determined by choosing an option in a dropdown selection and subsequently pressing Load data. I have so far written the part where I can load the data from the different types of datasets and display them to judge if any data needs to be excluded. after all data in the set is judged for inclusion, I have several matrices and cell arrays that need to be kept for later processing. I wanted to keep the number of properties limited and each dataset contains similar matrices and cell arrays (data[x,y,z] with the values, filenames{x,y} with the names of the file etc.) that later on can be processed in the same way.
In matlab I would store these different matrices and arrays in a data structure that I would name according to the dataset I'm loading. However, I cannot manage to do this in matlab appdesigner. I already made the matrices and cell arrays as properties so I can access them in different parts of the app.
I was wondering if there is a way to group these in app designer so I can have a specific name, e.g. 'CurrentClamp', under which I have the properties: 'data', 'filenames','etc.', or named 'VoltageClamp', under which I then also have the properties: 'data', 'filenames','etc.'
I define them now as follows but in this way I would have to make many properties and add the type of dataset to their name.
properties (Access = private)
data = [];
data_filename = {};
excluded_data = [];
excluded_filename = {};
end
Thank you in advance.
0 Comments
Answers (1)
Tejas
on 20 Feb 2024
Hello Anouk Heuvelmans,
To efficiently organize the four properties ('data', 'data_filename', 'excluded_data', 'excluded_filename'), I recommend creating a class to encapsulate them. This class will contain all four properties, and each instance of this class will represent a cohesive group possessing these properties.
In the example provided, I have created a file named 'Dataset.m' located in the same directory as the App. This file defines the class with all the desired properties.
'CurrentClamp' and 'VoltageClamp' have been introduced as objects of the ‘Dataset’ class within the properties section. The 'startupFcn' is utilized to generate instances of the class, with each instance corresponding to one of the multiple datasets.
Additionally, I've implemented a function called 'Load_data', which shows one of the ways to assign data to the properties of the objects (‘CurrentClamp’ and ‘VoltageClamp’).
Below is the code, as well as a screenshot of the output.
Dataset.m
classdef Dataset
properties
data
data_filename
excluded_data
excluded_filename
end
methods
function obj = Dataset()
obj.data = [];
obj.data_filename = {};
obj.excluded_data = [];
obj.excluded_filename = {};
end
end
end
Properties Section
properties (Access = private)
CurrentClamp Dataset
VoltageClamp Dataset
end
startupFcn Callback
function startupFcn(app)
app.CurrentClamp = Dataset();
app.VoltageClamp = Dataset();
end
Load_Data function
function Load_DataButtonPushed(app, event)
app.CurrentClamp.data = rand(8,4);
app.CurrentClamp.data_filename = {'CC_File_1.dat' , 'CC_File_2.dat' ,'CC_File_3.dat' };
app.VoltageClamp.data = rand(8,4);
app.VoltageClamp.data_filename = {'VC_File_1.data' ,'VC_File_1.data' ,'VC_File_1.data' };
end
ScreenShot 1 : shows the contents of ‘CurrentClamp’.
ScreenShot 2 : shows the contents of ‘VoltageClamp’.
This solution is tested on MATLAB R2023b.
For more information on Classes and Objects , refer this documentation : https://ch.mathworks.com/help/matlab/matlab_oop/why-use-object-oriented-design.html#:~:text=Reducing%20Redundancy,and%20return%20values .
0 Comments
See Also
Categories
Find more on Tables 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!