Week+of+12-10+to+12-16

December 12th
Today I arrived at QuarkNet at 4:30. It was time to dive into Chapter 2 of the textbook. The intro discussed concatenation and arrays, both of which I am very familiar with and have already dealt with in this logbook. Section 2.1 focuses on strings. This was all review, aside from a couple new useful commands for manipulating strings. Below is a screenshot of a few of these methods in action. (Yes, I realize the second line is pointless) 'num2str' and 'str2num' are simple conversions of the data from one type to another, but note the original variable is not changed (it would only do so if I said something like age=num2str(age);). 'length' returns the number of characters in a string, as shown by the example above that includes everything, even spaces. 'upper' and 'lower' change the case of every letter in the string. Finally, adding a numerical index after the variable displays a certain character or group of characters (for example the last line produces the third through ninth characters). Section 2.2 discusses the 'disp' command which I already am quite familiar with. Section 2.3 explains user input, which I utilized in 'PiggyBank'. Section 2.4 discusses vectors. They call one-dimensional arrays vectors to distinguish them from matrices, but I will likely call vectors simply "arrays" and only specify further than "array" for multidimensional arrays (such as calling matrices "2-D arrays") out of habit from my past experience with them. 2.4 discusses the raw basics of input, indexing, and changing a specific spot, which I already have gone through in this logbook. The one interesting new function in this section is the transpose operator, merely an apostrophe, which, if placed after an array's name, will swap the rows and columns of an array. Below is an application of this idea. It is essentially like reflecting the matrix across the diagonal line made by the coordinates where the row and column number are the same (in this case 1 and 5 lie on that line, and the other numbers flip across the line). Section 2.5 does a detailed breakdown of vector operations. I am already familiar with operations by scalars, element-by-element operations, and how to tell MATLAB to do them, but one tool was new. This was the idea of taking a "subarray" out of an array. Code is the easiest way to show this: Obviously, adding 3:9 in parenthesis after the vector name returns the third-ninth numbers in the vector. Also, the word 'end' in place of the second number would obviously go from the indicated point to the final one. Finally, putting a bracketed array of indexes enables MATLAB to generate a specific list of indexes rather than a group that are all indexed in a row, as shown in the last line of code. These techniques of grabbing parts of arrays (as well as its 2-D counterpart, which I am guessing will come up later in the text) will likely be very useful in pulling only parts of data sets out in order to perform operations, such as the one in that screenshot but with real meaning and usefulness. Section 2.6 introduces some functions useful when dealing with vectors. I played with a few of them in the Jing shot below. Zeros, ones, and rand create a vector of dimensions (rows, columns) that you input; zeros makes all zeros, ones makes all ones, rand makes each number a randomly chosen number between zero and one. 'linspace' contrasts the colon operator, one function I encountered in the tutorial. While using colons is a structure of start:increment:end, 'linspace' asks for inputs of (start, end, number of terms). It it obvious which situations one or the other would be useful in. 2.6 also lists statistical functions: max, min, sum, mean, median, mode, std (standard deviation), and sort (returns the vector with numbers in ascending order). Other than my parenthetical explanations, I would say this group is pretty obvious and doesn't warrant much discussing. Section 2.7 goes into a bit more depth about random number generation in MATLAB. 'rand' and its integer counterpart 'randi' are MATLAB's ways of generating random numbers. I have already discussed 'rand' enough, and the only difference with 'randi' is that it requires a third input at the beginning that binds the end of the region the random number should be taken from. For example, below is a list of 9 random numbers from 1 to 10. The final tidbit with random numbers has to do with the capability of the computer. The author pointed out that no program can create a truly random number or set of numbers, but there is a way to make an already extremely random choosing process even more random; if you enter the line at the beginning of a program, it will initialize a clock-generated variability in the random number generator for the remainder of the program. That concludes chapter 2, and conveniently my day as well. It is 6:30 and I am leaving QuarkNet for the day.

December 13th
I got to QuarkNet at 3:45 and began on Chapter 3. It's about plotting, so I'm guessing I've already covered a good amount of it in my earlier logbook posts about plotting. Regardless, it can't hurt to go through it and pick up any missing pieces from the MATLAB tutorial. Section 3.1 explains that the 'plot' command asks for two vectors of equal length, one of x-coordinates and one of y-coordinates. It also has the option of inputting a style for the plotting - this ranges from lines between points to small circles as representation of the points, and can involve a variety of colors. Below are some Jing shots from a website I found with tables that specify the different indicators that can be used for styles. The section goes on to discuss different axis-scaling commands. The most useful is the one I previously discussed when creating my "Primitive Smiley", the 'axis' command requiring inputs of x-min, x-max, y-min, and y-max. There are a variety of axis commands, which it would be a waste of time for me to explain each of. But, I will copy a list below (maybe for later use) One thing that didn't click with me until I read this section is that you can't do any of the formatting work until after the plot has been generated. So, a program would need to wait until after the point in the code where the plot was generated to manipulate axes and such, and would have to redo formatting every time a different plot window was generated. Section 3.2 discusses the actual plotting of the variables and emphasizes the inependent vs. dependent variable relationship. This is essentially all stuff I covered with the parabola in "Primitive Smiley". Section 3.3 discusses bar graphs and histograms. Bar graphs operate similarly to regular plots. The unique thing is if only one vector input is provided, MATLAB creates a bar graph with x values of the index of each element in the vector, and the y-values of the actual data in the vector. The 'bar' command is the root of bar graphs. 'hist' governs situation with histograms. Obviously, I will want to know this for the time when I arrive back at particle physics. So, below is a little histogram I made with random numbers. The version of the 'hist' command I used takes two inputs: the first is a vector of data (which in this case is my set of randomly generated values from 1 to 10), and the second is a number of bins, "nbins" (which in my case worked out perfectly because as I set 10 bins, they corresponded with my 10 possible values). It is interesting to see that my random set created 14 8s, yet only 6 7s. I then decided to play with the bins a little bit in order to more fully understand how exactly MATLAB scales things, etc. Below is a slight alteration of the previous random histogram where the code is flexible for a set from 1 to a user-inputted upper limit. This example involves numbers ranging from 1 to 51, rather than 1 to 10. MATLAB's histogram creator is very efficient in its division of the bins and creation of the bars, but the auto-scaling leaves something to be asked for. For the set from 1 to 51, MATLAB decided to scale the x-axis from 0 to 60. I thus had to adjust the axis scales. Note: I used "inf" as the upper limit for the y-axis, which essentially tells MATLAB to auto-scale that portion, because the y-values are unpredictable because of this random set. Since the user is binding the range of x-values, I would prefer they be very clear so the user knows exactly what group of numbers they are looking at and which values fall inside which bars. In my first example, with numbers from 1 to 10, the axis labeling was surprisingly poor, because the accurate depiction would be to have each number in the center of its bin, but instead 1 was on the far left of its bin and 10 on the far right of its bin and the others dynamically between, which is actually a somewhat inaccurate portrayal of the data. The scale in this second example was slightly better, but that is only because of the scaling I built into the programming. As I said, before I changed that, I got ugly scales that made the data very unclear, and MATLAB seemed to be afraid to use values in the scale that were not multiples of 5 or 10. Section 3.4 addresses putting multiple plots on the same graph. I already did this with "Primitive Smiley", so the 'hold' and 'legend' commands are familiar to me. The one new insight I gained about 'hold' is that, although you can compound multiple plots without it, if you want to combine multiple plots of varying types (say, lay a line over a histogram), 'hold' is the only way to accomplish this. Two new, but simple, ideas were the ability of the 'plot' function to actually plot multiple curves in the format plot(x,y,x,y.....x,y) and the idea of using ellipses (...) if the parameters are so long that you feel the need to carry things into a new line. Section 3.5 discusses the 'line' and 'text' commands. 'line', for all intents and purposes, works exactly the same as 'plot'. You enter a vector of x-values and a vector of y-values. The difference is if you want to change the appearance of the line you add a third input 'Color' and a fourth input of the color (or abbreviation for said color) you desire (as long as MATLAB is familiar with that color). 'text' asks for coordinates to start the text at, a string of text, and then optional color and font specifications. The color specifications work the same as the ones for 'line' and the font and font size are also out of the same format. This is going to be a theme in MATLAB stuff - the author of the book calls it a Property-Value pair when you give something like 'FontSize' as one input and a size as the following one. Below is a somewhat messy example of plopping text onto a plot. I wrapped things up around 5:45 today and headed out soon thereafter.
 * [[image:Line_Types.png width="464" height="168"]][[image:Colors.png width="457" height="320"]] || [[image:Marker_Types.png width="462" height="526"]] ||