Difference between revisions of "User:DukeEgr93/TechSupport"

From PrattWiki
Jump to navigation Jump to search
 
Line 28: Line 28:
 
Plotting the second column of data versus the first would therefore look like:
 
Plotting the second column of data versus the first would therefore look like:
 
  plot(BlueFile.Voltages(:,1), BlueFile.Voltages(:,2))
 
  plot(BlueFile.Voltages(:,1), BlueFile.Voltages(:,2))
 +
==== Really Fancy ====
 +
You could get really fancy with structs by having a variable (in this example I call it AllVals) that has an index based on which set you are loading and what color you are using and then stores the voltages in a field called V.  For instance:
 +
load LED_01_Blue
 +
AllVals(1,1).V = Voltages
 +
load LED_02_Blue
 +
AllVals(2,1).V = Voltages
 +
load LED_01_Green
 +
AllVals(1,2).V = Voltages
 +
load LED_02_Green
 +
AllVals(2,2).V = Voltages
 +
will create a variable called AllVals that has four items in it.  The first index would be which set and the second would relate to a color.  If you wanted to plot set 2's Blue LED resistor voltage as a function of the total, that command would become:
 +
plot(AllVals(2,1).V(:,1), AllVals(2,1).V(:,2))
  
 
=== How can I make button presses switch tabs? ===
 
=== How can I make button presses switch tabs? ===

Revision as of 18:08, 11 April 2018

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))

Really Fancy

You could get really fancy with structs by having a variable (in this example I call it AllVals) that has an index based on which set you are loading and what color you are using and then stores the voltages in a field called V. For instance:

load LED_01_Blue
AllVals(1,1).V = Voltages
load LED_02_Blue
AllVals(2,1).V = Voltages
load LED_01_Green
AllVals(1,2).V = Voltages
load LED_02_Green
AllVals(2,2).V = Voltages

will create a variable called AllVals that has four items in it. The first index would be which set and the second would relate to a color. If you wanted to plot set 2's Blue LED resistor voltage as a function of the total, that command would become:

plot(AllVals(2,1).V(:,1), AllVals(2,1).V(:,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.