User:DukeEgr93/TechSupport

From PrattWiki
Jump to navigation Jump to search

Questions and Answers

How can I see what's going on while the app runs?

There are a couple answers to this. The first is, if you put a

keyboard

command and the app runs it, MATLAB will give control of the workspace to you. The prompt will be K>> indicating that you are in keyboard mode. You can then look at variables (for example, type

whos

to see what variables exist) as well as run code to see how it changes your app. When you are done with debugging, type

dbquit

and the app will resume (including any changes you made while in keyboard mode).

You can also have the app put information on the screen the same way as you would in a function - by using disp, fprintf, or just putting a variable's name in a line of code to have it replicated on the screen.

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.SelectedTab = app.Tab2

where app.Tab2 will be the name of the tab you want to make active.

How can I put information into a data table?

Probably the easiest way to do this is to put strings in -- even if some of the information is numerical -- in order to have complete control over the formatting. Imagine you have a three-column data table and in each row of the table you want to have a word, a number formatted using scientific notation with three decimal digits (i.e. four significant figures), and a floating point number formatted with two decimal digits (i.e. three significant figures). You might have code that resembles:

app.UITable.ColumnName = {'Words', 'Scientific', 'Floating'}
app.UITable.ColumnFormat = {'char', 'char', 'char'}
Words = {'Lets', 'Go', 'Duke'}
Nums1 = 1000*rand(3,1);
Nums2 = randi([0 1000], 1, 3)/100
for k=1:3
    app.UITable.Data{k,1} = Words{k};
    app.UITable.Data{k,2} = sprintf('%0.3e', Nums1(k));
    app.UITable.Data{k,3} = sprintf('%0.2f', Nums2(k));
end