Programming with MATLAB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to this webinar programming with MATLAB my name is Jared okay and I'm an application engineer mathworks today I have three main objectives first I'd like to introduce you to MATLAB from the lens of a programming language a MATLAB is oftentimes thought of as a technical tool for engineers and scientists to do data analysis simulations or develop algorithms lamella there's also a full-fledged programming language and I'd like to highlight some of those capabilities also I'd like to introduce you to the various development tools that's built around it to support the MATLAB language I'll go through a couple of examples and through those examples I'd like to demonstrate how you can program effectively in MATLAB and also show you the various programming styles that malim supports ranging from interactive programming all the way up to using more formal techniques such as object-oriented programming so let's get into the example the example we're going to use today is on creating an automated analysis routine using MATLAB to choose the best location to build a wind turbine based on some of the measurement data that we have acquired from multiple locations so this is from the wind energy industry as you can see in the picture this these wind turbines are pretty large and very expensive to build so what they do is before they build one of these wind turbines or wind farms they need to first find the best location ideal location to build them so they do that by taking measurements at these various sites by measuring wind speed and temperature and so forth and based on that information they can try to estimate how much power they'll be able to generate if they were to build a wind turbine at that location so what we want to do is develop a program that would analyze read in those multiple files do those calculations and then identify what the best location is so the way they calculate the average power production is based on this formula here and it's essentially based on these two quantities the wind speed probability distribution which we can get from the measurements and also this curve which we call the turbine power curve which is something that characterizes the wind turbine that they're going to build based on these quantities they can multiply them and upgrade over it to calculate what the average power is going to be okay but we'll come back to this slide when we get to that section of the example but keep this idea in the back of your head as we go through the example okay so let's switch over to MATLAB this is the MATLAB desktop it's an interactive development environment IDE with various components really help you use MATLAB and also develop programs we have this tool strip with many of the controls that you oftentimes need to do your analysis in MATLAB and it's really designed to allow you to find the functionalities that you really need for your for your work inside MATLAB and we'll introduce the various components as they come up in the example but if we take a look at these various tools especially in the early phases in your programming it's very important to make use of these interactive tools because you need that way of a mechanism for exploring ideas so this interactively interactivity becomes really important so in this current folder you can see a lot of different files here's the file that we're going to be working with when data txc that's the text file ASCII file and if we take a look at what it looks like it's a columns of data five columns of information the first column is the time stamp with the various hours that we've measured and it's an hourly data from starting from tenth of June of 2007 all the way down to 10th of June 2008 so it's one years worth of data roughly 8700 data points okay and for each hour we have three speed wind speed measurements and measured in meters per second so these are three redundant measurements three sensors the same location to make sure sort of validate each of the measurements and then there's a temperature sensor at that site to measure the air temperature the ambient temperature and Celsius okay so the idea is to develop a a program that would automatically read in this do the analysis and then ultimately calculate the the estimated average power so that we can determine which location is the best okay so to help me create this program I'm going to be initially relying a lot of the on a lot of the interactive tools that's built into antonella desktop - to import the data I'm going to use this import data control and right in the home tab and here we can select the file that we want to import and it's going to display that in the this interactive import tool okay so all we see here is the preview of the data inside this file and it automatically determines what the header is and it's going to use those names as the data that's coming into MATLAB you can do some quick pre-processing for instance if I want to convert these textual represents a representation of dates into numerical representation or serial days we can do that by specifying the date format we can have full control of how we want to bring into MATLAB but then once we click on this check box MATLAB will scan through the file and it's going to automatically import those data points into MATLAB as in this case five different variables five different pieces of data corresponding to each column okay it brings it into the MATLAB workspace which you can think of it as my loud memory space every piece of information that Mel knows about will be shown in the mounted workspace browser okay so as you can see we were able to easily bring in the data from the data file but at the end of the day we would like to programmatically do this so that we can apply this to multiple data files well if we go back to the import tool we can ask MATLAB to generate a script which will essentially give you the sequence amount of commands to reproduce this process this action so you can see that it had just Auto generated this MATLAB script which has sequence amount of commands so these are all mounted commands to do the same thing that I've done through the tool interactively so you can see where it's specifying the the data file okay for those of you have who are familiar with MATLAB a couple of functions that I like to highlight is text scan to read in the data files data from the text file and also date none for doing the date convergent okay but I can the easiest way to make use of this is to simply save it and then I'll call it import data file and once I save it I can immediately use it to reproduce what I've done interactively here the the file that I saved will now show up in this current folder and just to test this out I can go ahead and clear the workspace or alternatively I can just type clear it's going to do the same thing and now I can type import data file into this command window and it's going to run those sequences of commands that was in that file on that script and it will import the five variables that I added that data file now this command window is it is really the the the main interface to the MATLAB language this is where you can type up commands and functions and get immediate feedback it's a highly interactive environment and you can think of it really like a sandbox where you try out ideas which is extremely important in the early stages of programming okay once I have it in one of the components that you might make use of very frequently is the workspace browser now this not only gives you the information on what kind pieces of information that you have available to you but also gives you some basic statistics descriptive statistics about the data so these are all column vectors and you can look at what the minimum maximum values mean median and so forth and there are a few other things that you can choose to include such as variance okay now you can see if you look at this temperature for instance we can see that the lowest that I got the quota stick out was minus 15 degrees Celsius hottest was 38 the range of 53 so you can get some quick view into the data and then do some quick analysis visually looking through the workspace but oftentimes you might want to use that information in other parts of your program so rather than looking at this interactive component you might want to access have a programmatic way of getting that information well Mawlid is a full language mountable own has thousands of built-in functions for design for scientific and engineering tasks to help you use those functionalities MATLAB has a very rich documentation as well as tools to really help you find the things that you're trying to do so from the function browser you can search for functions or browse for core functions for instance mathematics statistics descriptive statistics and you can see here you see the functions that apply the correspond to the stats that you saw on the workspace browser ok and if you hover over one of them you can see a short help text on how to use that function or click on more help to get a full function reference page which has syntax and description and examples that you can copy and paste and then use that to modify for for your own use okay so so in our case maybe if I want to programmatically find the minimum value I can simply say men of the temp and it'll give you the same result that you saw in the workspace browser now what if I wanted to know when that minimum temperature occurred when was the coldest time throughout the year during the year well what I need to figure out is where when this occurs where in the vector this occurs and then find the corresponding point for that from the time variable okay well if you look at back at the light documentation we can see that there are other syntax that you can use so if you ask for the second output you can say figure out when where that occurs so in the 449 87th element of this temperature variable is when this minimum temperature occurs but now that I have this information I can figure out when that occurs by indexing into the time vector and we can see that this is when that occurs now obviously this doesn't really make sense to me it's a serial date representation which means something the MATLAB but it's not really human readable but if we go back to our our our function browser and look for functions that's related to dates you can see that there are a number of conversion functions so we're going to make use of this dates tour which allows you to convert the data and time information to string format okay so if I go ahead and say a time of I DX you can see that this -15° occurred 4th of January 2008 at 2:00 a.m. all right okay so going back to our problem we we see that well there are some really cold days and if you think about where the sensors are located this is located in open air and one of the thing that people are concerned about in this application is that some of the sensors might get frozen if the if it's too cold outside and maybe there's some moisture in the air so if it's a frozen sensor the reading that you get out of it is not valid so before we go further with the analysis you want to first do some data cleaning and do deal with some bad measurements okay so in our case we have temperature and speed information so what we can do is we can make some assumptions and say well if the temperature is below freezing is very likely that the sensor might be frozen but that alone is not enough it may be below freezing but the sensor might be just fine so we'll also look at the speed information and say if the speed measurement is close to zero meters per second so if it's not recording any any speed so if both of those conditions are met then we can assume that the sensor might be frozen okay so that's the logic that we're going to use so how can we do that now that's this sort of task where based on the data finding something that meet a particular criteria that's very easy to do in MATLAB because of the matrix nature of the language but let me first use a simple example to illustrate that idea so I'm just going to create a test vector random permutation of eight numbers so in one through eight in random order now let's say from this list of numbers I wanted to identify and automatically pick out all the values that are less than four so 3 1 & 2 well amount lab what I can do is I can simply ask that question a less than four and what that returns is what we call a logical array logical vector logical meaning zero or one zero meaning false one meaning true so we can see if we line it up anywhere you see a 1 anywhere it's a true indeed these numbers are less than four okay so this comparison did that test for each of these elements and gave me true or false once I have this I can actually use that to index into another array or or itself in this case and one and when I do that it's going to pull out just the values where they're once so I pulled out 3 1 & 2 we're going to do do the same thing we're going to find all the places where the temperature is freezing pick it out figure out all the places where speed is close to zero and then take it out and then we can deal with those bad bad measurements now just for simplicity for this this webinar what I'm going to do is I'm going to work with the average of these three measurements instead of looking at all three different measurements and this is just purely just for simplicity in this example so from these three column vectors I'm going to first create a a single matrix that contains all these three so one two and three just going to concatenate it so by putting it inside a bracket and separating with a comma it's going to place them side-by-side so now you can see 8776 by three so the three means that has three columns okay so I created a single matrix and now what I want to do is on average going across average these three numbers get a single number average these three numbers and so forth do that for all the rows okay well the the command for that is mean is the our malfunction for calculating the average so I'll say however speed equals the mean of all speeds but then we can we quickly see that this is not what we want because my lab is an interactive environment you type a command it will immediately return the result and you can use that interactivity to really verify what you're trying to do is indeed correct so in this case I got a result which I didn't expect I expected a another column vector for each of these rows but instead I get just three and that's because of the matrix nature of MATLAB many of the functions in MATLAB are really designed to naturally work with matrices and has a default behavior so for two-dimensional matrix like this it applies this operation by default along the first dimension which is down the columns so that's why you see three numbers which are averages of each of these columns but if you go ahead and take a look at a different ways of calling the mean function you can see that I can optionally provide a dimension which in this case if I want to go across the rows I want to go across the 2nd dimension and now I get a column vector and this is exactly what I want now from now on I'm actually going to be starting I start using a semi-colon just to suppress the output so it's nothing different than before but by using a semicolon it prevents from displaying the output into the command window it will still still do the operation okay so so now that I have this average speed and temperature let's try to figure out those icing conditions for for temperature I want to find one temperature is less than freezing but I'm just going to be a little bit conservative and say less than two degrees Celsius I'm going to say it's as close to freezing approaching freezing temperature so with that single command I was able to immediately find zeros and ones where it corresponds to where the temperature is less than two I can do the same thing for speed and for this one or the average speed I can ask for exactly zero but these are real measurements so I may not get exactly zero so I'm going to again do something that's a little bit more conservative and say if it's less than one meters per second I'm going to say it's a very low speed might be stationary not not sensing anything okay so I have two vectors of zeros in true and false and what I want is both of these conditions to be met so my final is idx ice temp and idx ice speed so this end will do a element by element comparison so if both elements are true and it will be true if only one is true or none and it will be false all right so these three commands allow me to quickly identify those icing conditions based on these criteria that I've specified okay but I've been using that for a while so it's it's a pretty obvious to me that this is doing exactly what I expected but it's always good when I'm creating these programs is to to verify that I'm what I intending to do is is what I'm actually getting so a best way to do that well one way is I can open up this variable and then through this variable browser I can quickly look through and see where I see ones and zeros but a better way might be to graphically confirm okay so visualization is a very common test in a MATLAB so we have a dedicated tab for plots so if we go ahead and say let's look at a temperature and average speed and we're going to plot them as a scatter plot okay so it may not look make a lot of sense but we're looking at temperature across the X and then average speed across the Y and if I'm what I'm looking for is temperature less than two degrees so something that's I'm going to use a annotation to just to draw on the screen but something less than two okay so something like here for temperature and average speed less than one so something that's probably here so I'm essentially looking for something in this lower quadrant lower corner and if I did it correctly I am I'm I should be able to successfully just pick out just those points okay so we can verify that graphically by let's overlay on top of this the the icing conditions I'm going to in order to overlay I'm just going to hold this figure and then I'm going to say scatter temperature of I DX ice and then average speed of I DX so this will pick out just those icing conditions sighs I'll just keep the scatter size the same and then I'll use a maybe red okay all right so now we can see maybe I can zoom in right so that the bottom part is where you see the red dots okay so I'm very that I'm I was able to successfully pick out the points that I identified as the icing condition okay so now that I know what the the icing condition is what I can do is I can try to deal with it and this really depends on the analysis that you're trying to perform for this case for simplicity what I'm going to do is I'm just going to simply remove those icing conditions from my measurements so that it's it's completely out of the data set okay so I'm just going to say average speed of the icing condition and set that to empty and that's going to remove those points and now we can see when we look at this that now the number of elements is 87 62 compared to the full data set hat 8776 so 14 icing conditions that we removed from the data set okay so now that we have this what we can do is we can look at perhaps the histogram okay because that's one of the quantities that's required to calculate the average power so here's a histogram that we can use and and here we go okay and note set as I been clicking on these plotting commands and the command window has been echoing the the equivalent commands so it's not as teaching me what these commands are so if I ever want to do it myself without having to go through these interfaces I know exactly which commands to use okay now histogram just like with any other amount of function their default behaviors such as the number of bins that it chooses to use so the default is going to choose ten different bins but if I want higher resolution I can actually specify that as you can see in this this syntax hint and I can specify the number of bins or specific bin locations so I can either specify either of those things okay so let's create a bin that goes from 0 meters per second all the way to the maximum of average speed okay and by using this colon shorthand it creates a linearly space vector that goes from zero to beginning to the end and increments of 1 by by the D by default if I want a different interval I can specify a third argument here in the middle and now I'm going to increment by 0.5 so 0.5 1 1.5 and so forth all the way to the maximum which in this case is 21 so now that I have this I can specify speed bins as the bin locations and now I have a higher resolution histogram so by looking at this we can tell that majority of the time windows blowing between 5 and 10 meters per second sometimes it's very no wind sometimes as was as high as 20 meters per second but now we have a pretty good sense of what the distribution of the wind was throughout the whole year all right so if we quickly go back to our slides that's the first half of this equation we have identify this wind speed distribution now we just need to identify this turbine power curve and then we can we're on our way to the average power alright so up to this point I've been heavily using the command window because I wasn't entirely sure what the approach was going to be so I needed this environment that allowed me to interactively try things out so command window was the perfect place I used made use of a lot of the interactive tools like the plus tab and the Home tab and and looking at the workspace but now I'm at a point where I have a pretty good sense of what I the direction that I want to go with with this program so now I will not start to formalize my my process so I'm going to do this by starting to create a script of these commands that I've been typing in the command window well I'm going to go to the command history which has been recording all the commands that I've been typing into the command line or what MATLAB didn't type it into command line and so it has a commands that goes all the way back to many many days and it's a great way of going back and figuring out what you did before and picking out the commands that that might be useful so let's do that in our case we imported our data and we calculated the average speed and then we try to identify the icing conditions maybe this where we verify that the icing condition was but there remove the icing data points and then plot a histogram okay so let's say these are the commands that were very useful and I like to capture them so I'm going to go ahead and create a script out of this so now my lab has just picked out those commands that I had highlighted and then gave me a brand new MATLAB script that has just those commands okay so now I can go ahead and save this just give it a name my analysis okay and once I save that it'll show up here and now it allows me to run all these commands from start to finish sort of in a batch fashion so let me just clear the workspace I'm going to close all the figures and let's clear the command window so now I can either hit run here and run is going to essentially run this my analysis you can see that it ran through all these twelve lines of MATLAB commands and then ultimately gave me this last plot which is the histogram so now we're really approaching a the point that we're starting to create this program that goes all the way from start to at eventually to the to the end of the analysis okay but as I'm creating these programs it becomes really important for me to to start annotate annotating so that I have some information regarding what I'm what I'm doing my analysis so import from text file calculate average speed identify I sink condition and then histogram alright so I can create comments by using this percent sign and this is a purely for for the reader or the user of this MATLAB program to to explain what's happening for different parts of the program I can also break this up into bigger sections by using double % so this is a data import and prep okay pre process so this is or or my solicit data cleaning and we call this part visualization okay so you can see that as I use these double percent signs it now logically breaks up my my script into these various sections and the nice thing about this this the section is that now I can run individual sections in isolation so I have my cursor here in this section I can click on this run in advance that's going to import and do the program data prep now I click on run and events it's going to run these to do the data cleaning okay and then we can do some visualization all right so this by by structuring it this way allows you to kind of focus your attention to specific sections and you can iterate and change make modifications and and see if it if it's what you're trying to do by by running just that section it makes it really easy to fine-tune the program that you're creating okay let me open up a completed version of this this example and you'll quickly notice that it has more annotations a lot of comments to describe what the problem is but you also recognize some of the similar some similar commands that we've been looking at plug commands there's some commands for adding labels and titles here's where I calculate the average here's where I calculate the icing condition and so forth so let's let's actually try to catch up by going here in this running section by section and you'll see some different visualizations that we have in this script calculate the average icing conditions actually I think I'm running a different version of it so I'm supposed to do this later so let me bring it back to the wind data version all right all right that looks better icing conditions and then here's a histogram all right so that was the first half you go back to the slides real quick you can see that the next part is to identify this turbine power curve and the way we do that way the power curve is defined is that it's characterized by some parameters he's at these velocity locations that cut in velocity the rated velocity cut out velocity but this describes how much power a wind turbine can generate based on how much when what the wind velocity is so obviously if not enough when it's blowing is not going to generate any power also if the wind velocity is too high it is dangerous for the wind turbine so they actually shut shut down the wind turbine so it doesn't generate any power there is a sweet spot region 3 where generate step maximum amount at the rated power then region 2 is represented by this equation here that gradually increases based on when velocity okay so to represent that in MATLAB is pretty straightforward these are the different parameters and then we go with the region two first which is the defined by that equation as you suggest that you saw in that the slides and then the rest of that we make use of logical indexing we saw before if it's the low cut end velocity cutting speed then it's zero if it's above cutout speed then it's also zero and if it's in that sweet spot then it's going to be the rated power okay so with that we can go ahead and quickly plot what the turbine power curve looks like for this particular wind turbine okay once I have this then it's just calculating that integral and we're just going to use the the simplest way since we have data points for each of the bins we're simply going to multiply the two quantities the probability distribution and the the power curve and then we're going to sum up all the products and essentially we're getting calculating the area under the curve and that so that's going to be the the average power now in this industry they they actually represent average power as a fraction of what maximally they can generate so as a fraction of rated power and they call this the capacity factor and then they're going to use that this quantity to identify what's the best location so in this case we see that with the rated power of one mega watts this location can generate average of 270 Kittel kilowatts which has the capacity factor of 27% okay we can now do this comparison with the the other locations okay so so typically at this point I've at least finished I'm finished with the analysis but now what we want to do is uh we want to apply this to all the other data files but before we do that we may want to summarize this maybe print this out and make sure that this algorithm this analysis routine is exactly what we want so we might need to share this with other colleagues see what they think and see if they see any flags or any changes that we need to make so obviously one way to do this is to just print out this script because it's well commented has all the information so they can take a look at it if they want to run it they can load it into MATLAB and they can hit run but what we can do is we can take this script that's already well annotated and then publish it so right next to the editor tab is the publish tab you click on publish button and it will run through the script and then it will generate automatically convert that over to a report based on the annotations we have in the script so all the section headings became the sections within the report you click on any section it will take you to that section with the MATLAB code embedded inside and any figures that a generator is a embedded inside the report okay if you have any comments within the section they become text so there's a one to one relationship mapping from comments to text and then if it has any command line outputs it'll also capture that as well so this becomes a quick way of taking a working MATLAB script and then generating a report that you can easily share with other people ok this publishing capability has additional settings you can change such as the the output file format where you can output to XML law Tech doc a Word document PowerPoint and PDF alright alright so let me switch back to the slides real quick and we haven't finished the the the example yet because we need to apply this to old files but let me just summarize what we've done up to this point so this first half was all about introducing you to the MATLAB language and the interactive programming styles that and the functionalities that's surrounded around this interactive programming style so all the the command window that works basically the the tool strip was a Home tab in the plots tab all those interactive interactive tools are not just there to make it easy to use but there's a path ways to generate MATLAB script out of it so it's really to help you create a program down the road okay but at some point we migrated over to a script because we wanted to formalize the some of the commands that we were using and then we started to annotate add sections and then once we have it with sections then we can just publish it and automatically generate a report out of it alright so we've been using a lot of different techniques using a command line using variables and putting things into scripts and we haven't talked about these but essentially we need we may need to start using additional techniques to really solidify and formalize the functionalities that we're developing we are the programs that we're developing so the the ultimately what we're trying to do is that we now have a working piece of program now we just need to make it better we need to make it better because we need to apply this to many files if we're doing this thousands and thousands of times for different files we want to make sure that our program is it written as efficiently as possible so we need to make sure that it's a reusable in general and robust and also maintainable so that in the future if you need to upgrade it it's in a state where we can easily do that okay so let's go back so one of the easiest ways is because we've extracted out the file name information we can go in and change that name so if we have another another file here called a tower location one I can simply say tower location one and then hit publish and now it's going to do the same analysis but for a completely different data file so we're almost at it already at a state where we can reuse this for different files but it's a very manual task I have to go in and manually change the file name if I have thousands of files it becomes a very tedious task so to make this easier what we can do is we can convert the script to a function which has which we can create input arguments where we can input file names and then it will automatically apply that for whatever file name that I pass in and then we can do that programmatically by passing in a list of file names okay and you can easily convert a script to a function by starting starting with a keyword function and and we can alternatively have an input so if I want to say file name as the input to this function we can do that now if I go ahead and let me just save this to a different file when we do that you can see that there are some colors that's indicated here and this is the MATLAB code analyzer that's constantly running in the background and you may have seen this in the previous script that I've been working with but the the code analyzer is a great tool to really help you identify any inefficiencies that you might have in your in your program or even syntax errors so you can see here to identify multiple locations and for this one it's saying that you have defined file name but is you're not you really using it because as soon as I go in I override it with a different file name so that's easy to fix I can simply comment this out and now it knows to use this file name that's passed in you can see the code analyzer remove the warning okay so I can make these type of changes but before ice invest any more time on this one of the things that I want to make sure is that this script is running as efficiently as possible because I may be running this many many times okay so in MATLAB just open up the original function again there is a tool called a profiler that allows you to really run your program and determine which parts are taking a long time to run okay so in the editor tab I've been clicking on the Run button to run scripts but and also run in advance to go through different sections but here there is a control called running time which allows me to profile my program so when I do that you can see that after it ran it gave me this table of timings of how long it took to run different parts of the code as if I drill into the actual script it'll give you a table that shows which parts of the program it has been taking the longest to run so there is a significant amount of time taken to run these five different sections they take so these are actually a visualization commands that converts the numerical date representation to textual representation so it's taking a long time importing understandably takes a long time because it's reading from disk visualization typically takes a while but this gives you a mechanism for identifying those bottlenecks okay and if we scroll down you can see a color representations of the places that's taking a long time in addition to that you can see that there are a lot of hyperlinks so whenever you see a hyperlink you can actually dig in to all those individual functions even if there are math works provided functions so it really gives you the ability to dig in as deep as possible as it lets you and to determine which parts take taking the longest and then you might choose to call a function a different way or or chain I'll find a different function to use instead of the one that's taking a long time okay so really the profiler gives you the ability to really dissect your program and identify those bottlenecks now in our case turns out that we can deal with many of these issues pretty easily because ultimately what we want with our function is that final average power information or the capacity factor I don't really care for many of the intermediate graphics that it generates because that was more for the exploratory phase so I can get rid of all the graphics that's taking a lot of these times okay so if I already have done that here so I'm going to compare these two using a file comparison tool that's built into mount desktop so if I go ahead and say compare selected files it's going to display those two side-by-side and gives you a color code indication of the the differences between the files so the main difference is that you can see a lot of gaps here so we remove the plotting routine here we also remove this plotting and then we also removed this plotting here okay we did keep the histogram so histogram is still here but everything all the other visualizations I removed because it wasn't really necessary for the function version the other thing is that the the other benefit of a function is that it has this isolated workspace so it doesn't affect any of the data that's that exists elsewhere so it's a very controlled way of running commands but what that means is that if you want to provide share some of the data to the outside world you have to pass it out as an output argument to the function now in our case we actually have six pieces of information that we want to share with the outside world but instead of passing six variables around and having me manage all those six different variables one of the things I can do is I can combine all of those into a structure and a structure is a container data type in MATLAB which allows you to store different pieces of information inside a single variable so in this case when data is a structure and this is a notation you can use the dot notation to store additional information the temperature average speed power capacity factor a file name and plug that all the way all of them inside a single variable wind data and that allows me to pass out just the wind data variable it makes it easier to manage my my information okay so with that I can go ahead and simply call when analysis FCN when data.txt and it's going to run it for this file if I go ahead and do this for a tower location 1 it's going to give you a different result and you can see this structure is a displayed like this with a different piece of data fields displayed like this we actually did made one more change and I'm just going to briefly show this in the comparison tool which is you can add make this function a little bit more robust and reusable we may want to give the the option for whoever's using this for instance if I'm giving this to one of my colleagues the the option of not providing a file name but if if they don't then it's going to display a dialog box which allows them to pick out a file manually as and then it's going to do some validations to make sure that the file exists so there's some error checking to make the code function a little bit more robust ok so if you go out and say function - but if I don't passing any file and then now I'm presented with this dialog I can go ahead and select the file and then makes it a little bit easier for people to use ok or if I pass in some file name that doesn't exist hello dot txt it's going to say because there's an error checking it says file hello.txt cannot be found so it has a nice mechanism to catch that problem as well ok all right so ultimately well we have a function that's that can be now applicable to multiple files and finally to automate this we have this automation script which first identifies those files by using the dir command okay and what that does is that it figures out what these file names are so let me just run these three commands here all right so and then if we take a look at what files that name looks like you can see that it was able to automatically pick pick out a six file names so this way I can have a folder with thousands of files I don't have to manually type anything I can just let MATLAB determine what those file names are but once I have them I can go through each of them one by one using a for loop a loop and for each one I call wind allows this function or function to either way and then I'll store the result into an array of structures then afterwards I can go ahead and figure out which one had the maximum capacity factor okay so let me just publish this so you can see what the final result looks like you'll see five different or six different histograms pop up and then a bar chart and then a report okay so it automatically process the six files and then determine that the location for was the best location and this same script can apply if I next day come up with a hundred other data files I just put them inside this wind data files folder I can run it and now I have a new brand new report with many more data files analyzed automatically analyzed all right okay so what we did in that second part was all about making our program taking a working program and making it better by making it more maintainable using better type data types to store and organize our information using functions we made it a little bit more general so that you can oh by making it a function it made it more also you can pass and file names in an automatically process those files we added some validations and error checking we made it a little bit user friendly by providing an option for the user to select the file interactively through a dialog box we didn't cover it today but there are other things like using other function types to to better organize your program you can make use of packages if people are familiar with things like namespaces in other languages there's also a full unit testing framework which is a framework that allows you to really do a robust testing of your program and also the various tools that we looked at like the editor the deep code analyzer profiler we didn't actually get to look use a debugger but there's a full debugger and the MATLAB editor where you can step through code one line by line and see what's what's going on within the runtime in addition again we didn't have time to cover it today but there are other additional programming language features for those of you familiar with object-oriented programming MATLAB also has a full-fledged whole framework where you can define classes and with properties and methods and events but it's all built around the MATLAB language so it's everything is matrix based so you can have matrix and arrays of objects but you can create events and listeners and heritance and everything that you might expect in a full o language there's also parallel computing you can use our parallel competing tools to to extend what you've done on your desktop to additional hardware resources such as multi-core CPUs GPUs or clusters of computers to really scale up and deal with large problems whether it be in terms of speed or data size and in memory okay finally we always want to think about how we can share our resorts and package our results to share with other people we looked at generating reports as one example today but you can also create user interfaces in MATLAB such as the one you see on the screen and package them as a single app so that you can easily distribute them with a single installer file within MATLAB but also if you want to share that with someone who doesn't have MATLAB a license then you can also create standalone applications by using the MATLAB compiler or using some of the Builder products with the compiler if you want to target specific components like dotnet or Java you can also generate C code from some some of your MATLAB algorithms by using the MATLAB coder product so there these are all different ways they can share results from from from your MATLAB application alright so so in summary today was all about MATLAB for programming looking at the the MATLAB language but it's based on the whole matrix based nature of MATLAB and it's really designed for engineering scientist science but allows you to really make use of the full programming language to help you in those engineering scientific tasks okay we looked at some of the interactive development environments especially in the first half using the command window and the tool strip in the various interactive tools but then we slowly moved over to scripts and creating functions and and other more sophisticated programming tools that are available to you to create large complex applications we do have a lot of other resources available on our website some of the topics we talked about today we have dedicated webinars on it such as the object oriented programming or MATLAB for C C programmers we also have many examples and videos that you can find from our product page so if you go to our MATLAB product page you'll be able to find links to videos and code examples some of them are included in the product so if you have the product already installed you can go to the documentation and get access to them but if you go to our website you get a longer list of some of these examples and videos and finally there's Mount of Central which is more of a user community it is a user community where you as the user can share information there's a forum where you can ask questions and do discussions there's a file exchange where you can upload your code examples or download other people's code examples linked exchange to share links regarding MATLAB and various blogs that talks about different aspects of the math works tool chain alright so that concludes this webinar thank you
Info
Channel: MATLAB
Views: 135,125
Rating: 4.9485378 out of 5
Keywords: MATLAB (Programming Language), The MathWorks (Business Operation), Numerical Analysis (Field Of Study), Programming Language (Software Genre), Learning to Program, Learning ot wrtie code, Learning to code, How to Learn MATLAB, How to learn to write MATLAB, How to learn to code with MATLAB, Computer Programming (Conference Subject), How-to (Website Category)
Id: -JQPGKmHmPY
Channel Id: undefined
Length: 54min 59sec (3299 seconds)
Published: Fri Sep 05 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.