String based interface for inter-class communication
2 views (last 30 days)
Show older comments
Hello to all,
I have a question about accessing variables in classes by using strings. I have classes for several measuring instruments and each has several signals. I also have GUI where I choose instruments and signals in listboxes. Property of each instrument and signal is a string name, e.g. 'Meteostation' (instr.) or 'Rain rate' (signal).
I would like to collect the available instruments and their available signals and display it in the listboxes. Then, by selection of a particular instr. and its signal I want to update plot and access the signal for modifications.
Now I get strings by clicking on the listbox and access the signal in classes by passing the string to methods and inside the methods I use switch command to access demanded signal. I would like to define the signal name only at one place - in the signal class - to keep the code readable. This string name in the signal class should be the same which is displayed in listbox - it walks through two or three class layers.
Do you have any idea how to make this more elegant? Something like translator from strings to variables? Or the way with switch/case is OK?
Thanks in advance for any advices,
Petr
2 Comments
Guillaume
on 14 Apr 2015
Could you give a clearer description of your classes structure (an example classdef for the instrument and signal classes)? At the moment, I'm very unclear on what you're asking.
It would also help to use the proper terminology. Classes in matlab have properties and methods. You seem to be using 'property' to refer to something else and 'variables' to refer to properties?
Answers (0)
See Also
Categories
Find more on Waveform Generation 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!