User:DukeEgr93/TechSupport
Contents
Questions and Answers
How can I dynamically load files?
You will want to use MATLAB:Flexible Programming for this. Given that the file names have strings in them, you will also likely want to use a cell array to store the color names. Here's some code to help you figure out what to do:
- Cell arrays are surrounded by curly brackets; you can put different-size strings in the elements of a cell array; for instance, you could have:
Colors = {'Red', 'White', 'Blue'}
To access the string, you would put an index in curly brackets after the name of the variable; for example
Colors{2}
would return the string White. To load a file with a color name in it, you could use flexible programming to create a string with the appropriate load command and then use eval to execute it. For example, if you needed to load data from a file called MyVals_White_3.mat where the 3 comes from some variable Set then what you really want is the command
load MyVals_White_3
To create that with sprintf, you could use:
sprintf('load MyVals_%s_%d', Colors{2}, Set)
To make this printed command run, put it in an eval function:
eval(sprintf('load MyVals_%s_%d', Colors{2}, Set))
How can I keep track of the matrices I load
Your data files each have a matrix called Voltages so if you run the command
load LED_01_BLUE
you will have a matrix called Voltages available to you. The problem is, if you then run
load LED_01_GREEN
the Voltages matrix from that file will overwrite the original. You will therefore need to figure out how to keep track of the correct files. There are several options:
- Load the file, then copy the data to a new file:
load LED_01_Blue VoltagesBlue = Voltages
- Load the file into a struct:
BlueFile = load('LED_01_Blue')
At this point, there is a struct called BlueFile and within it, there is a variable called Voltages - since it is a struct, to access it, you would need to write something like
BlueFile.Voltages
Plotting the second column of data versus the first would therefore look like:
plot(BlueFile.Voltages(:,1), BlueFile.Voltages(:,2))
How can I make button presses switch tabs?
Create a callback for when the button is pushed and then add code to it that looks like:
app.TabGroup.SelectedGroup = app.Tab2
where app.Tab2 will be the name of the tab you want to make active.