MATLAB Basics – A Practical Look

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right just making sure we're good here um so i'm heather um hopefully uh we've interacted before if not um i uh work on the matlab product management team in the area of data science and i'm joined by connell hello everyone uh i'm right here i'm i'm conan desouza i've been working at the mathworks for about four years now um i'm a mechanical engineer by profession so not someone that's typically writing code but um hey you know what matlab helped me become a programmer and now you know from being someone that hated coding to someone that's working in matlab marketing right now i guess it's a pretty it's pretty pretty good job right definitely the same here actually i mean i tried a whole bunch of different languages and dropped out of every programming course possible but whenever i started i started using matlab i'm like oh okay i could do this so hopefully we can give you that same experience um we're gonna use a lot of examples so we mentioned that this is very practical um and you know basically the theme is going to be you know try things you know it's no longer a world where you're just looking at this blinking cursor trying to figure out what code to type you know you can click around try stuff basically use examples that's what we do we google it and copy and paste right um at least i do i don't know econo um google google's everything we're engineer we're practical come on and then we'll talk about some of the things that will help you just remember what's going on you know so even as you try these examples just remembering what the fundamental sort of philosophies and the way that the language is working behind the scenes that'll really help you and then we'll talk about some specifics that you'll run into a bunch like doing math i forgot anyway um that was supposed to be a mcconnell laugh but no yeah let me just make me laugh good hopefully you know i'll do that we'll do some math we'll get to doing math for sure doing math is fun it's like sleepless nights but especially if you're in grad school um so to get started we just i wanted to point out you know even if you have no matlab access you've never downloaded it or you you know whatever it is you don't have a license or anything like that you don't actually need one um nowadays you can actually just go right to the documentation just mathworks.com help and help me uh and you can actually just click on some examples and start right away and you can find them and run in browser um so for example let's pick a couple uh i had a good one here where was it it was about pre-processing so i feel like um data stuff is really important right so a lot of people work in matlab either with signal data like sensor data or you know spreadsheet types or you know text files those kinds of things and so as you see i'm scrolling quick pretty quickly because i wanted to find my example um but you can see there's so many different things that you can get started with you know if you're you know reading data from arduino or different kinds of ports working with big data uh so you know this is a good place to start anyway just try to figure out what you want to do and find the example yeah i i think i think i think we cannot stress enough how you know there are a lot of matlab users in the world so whatever you're trying to do has been done before right don't you don't need to reinvent we look at the documentation look up file stage we'll talk about file exchanges a little later but yeah good places to get started that's when i get started i don't like writing code i like to use someone else's work so exactly i'm sort of the one that i don't tend to take a course first and then i just i sort of do it and then maybe i'll take a course to fill in all the gaps yeah later on you know um so this is a great way to start so you can actually just open this right away so for me it says open in matlab online because i have a license and i'm signed in so if you have access you'll it'll open in a full matlab online but if you don't it'll just run right in the browser so you might not get that full you know with the workspace and things like that but you'll get to run the example you can try out some code you can you know i don't know just try things out and change it around and learn without having to do anything else but again if you if you have a license like through university or malebomb or your workplace you can use the full featured matlab online and so this is just through the browser this is just chrome and it went right to my example that i wanted to show so let's just go ahead and run it i mean without having to go through all this stuff i mean it's pretty straightforward i think um this is a section so we're gonna run this section all right cool uh and like i said even if you didn't have a matlab license or never used it before you can just run it right in the browser like this so let's take a quick look at what we're looking at so first we'll talk a little bit more about importing data but this is a data file that was created in matlab so dot matt that's a sort of binary format file that you can read and write efficiently in matlab so that's what that is again we'll talk more about files later and then um i'm just going to kind of go line by line here to kind of explain what's going on i think it's helpful i'm also going to minimize this so that's what we did here we just loaded this in and we can click on it and it just brings it right in no big deal um here we're creating a vector so this colon operator is just going saying to give me a vector that goes from one to whatever the length of speed is and so uh that's one thing that's really important in matlab you know the one well it's matlab it's the matrix laboratory so that's kind of a hint to how things are assumed in the background um you know because everything's a matrix even a scalar you can see here it's a one by one right so um but so something to keep in mind and so we're always creating vectors we're using vectors and matrices so let's say we wanted to just create you know something like this one through tat that's sort of the colon object just does that it assumes you know one a spacing of one you know you could also you know change it up a little bit maybe something like this so um that gives you you know sort of your baseline a lot of times especially if you're doing mathematics like your algebra you know numerical methods and things you need to sometimes create your own uh vectors and matrices so that's a good way to do it and even when indexing we'll see that this will be really useful yeah i think the other thing to note is this is this is typically for the new matlab users you don't need to declare you know you don't need to declare the variable types and stuff that you just say a equals one to whatever and you're good to go you know which is a good thing about c because i i hate the syntax i hate the in whatever you know like it doesn't make sense in my head so right exactly and you don't have to you just start right away yeah um and then you can deal with it later like we'll see you know maybe there is you know some things we need to think about and you know it'll help you along the way you don't have to just start by typing a bunch of stuff um okay so so we have a vector right so let's go back uh to our x and so let's say um because we have a lot of signal people signal processing uh kind of stuff maybe we want to do uh take the sine of this vector so maybe we want we did from like zero to two pi or something like that so it's something that's important um in matlab you know a lot of you have these arrays or you know vectors matrices the functions oftentimes will operate on the entire thing and so that's sort of one of the fundamental things i think to keep in mind that you know i guess if whenever you're attending especially if you're coming from other languages if you're tending to write a lot of for loops you know oftentimes you just need to pass in the array itself you don't need to go through all that so we call it vectorization yeah so to speak yeah it's it's almost like if you're if you're writing for loops in matlab more often than not you're not doing it right it's it's it's it's a good it's a good assumption to make right exactly so let's do something a little bit more tangible you know this is a good example it also shows how to run um or how to call functions basically so this is one thing i liked about it i think like economic message i don't have to start with like headers and integer things or whatever um you know it's just like math basically um so you know it's or like excel or whatever if you'd use that before you know you just call the function pass in the uh data that you want to operate on um so again just kind of giving you a sense of how things work so that you you know get used to it so we're bringing we're working on this wind data in this example so let's just take a look so we have um our matlab workspace so this is where our you know variables that we're working on are stored and we have our direction humidity you know different things about the wind so uh let's say we want to try to add some of these things together or do some math we're getting to do in math already so put a few steps ahead that's right that's right we're going to jump around a lot trust me um so let's say like we have an equation that adds these two things together okay let's just try it so um direction and humidity were both uh 186 by one vectors we get back a vector of the same size and so again that's kind of how things work if you're operating on things together like that you're gonna you know expect the same kind of size at least for many of these operators um let's try a couple others so um maybe let's see we got i don't know i'm gonna do it on purpose so i get an error i think okay so i tried to take c which is this 186 1 by 186 and x which is 1 by 19. and so this is sort of a i guess linear algebra violation you know you need these things to line up or have the same elements um so when you get into linearizing i love it um but we'll just kind of talk about enough to get you uh through basically um so just keep those assumptions in mind you know if you're adding and subtracting even multiplication you usually want those things to be the same size um matrix multiplication i guess would be the one exception um so again it's something to keep in mind conol and i were talking about some of the most common errors and this is definitely one of the most common ones it's the most frustrating one as well yeah so and i think it happens a lot too at least for me whenever you are say you're bringing in data from like a web service or something else or you're loading a map file that has a different arrangement like 186 by one versus one you know one by 186 so uh you know those are cases where you need to keep this in mind you might find those errors or um you could let's see let's try another one let's see mean speed um this one there we go so um what happened so if we look at a and s that's the default variable um it's now a 186 by 186. and so what happened is i was trying to subtract if we go back hit the up arrow that's just our last typed um syntax so we tried to subtract 186 by one from a 180 one by 186 and so it's basically like this right so if you use matlab a long time ago you would have gotten that error um now we actually understand that you know people often want to do that in a mathematical way so it'll expand so that's just something to keep in mind you know i think this is you know some people want that in a mathematical way other times you might just be trying to um you know actually do it this way but it's it's giving you something uh that's wrong so you might get an error or you might get a weird matrix that you weren't expecting um but one thing to do is just use a transpose so that was you know that'll just straighten it out so flip the dimensions basically so uh so heather so so uh another thing that that that i use pretty often is the dot operator do you want to talk a little bit about that and how that how that affects matrix computations absolutely yeah so uh the dot operator so uh carl mentioned uh this would be something like all right let's go back to our x and y right so we mentioned something like that it's array or no element by element right but so if we did something like uh like and so you know we're getting some kind of that we're getting this error it's incorrect dimensions i don't know what's going on why is this happening i just wanted to you know do the elements by accident the elements by y what i can do is just use this little dot and that tells it to just no no go element by element don't try to do um you know linear algebra multiplication so that's so much good sorry so so this is something that that you'd use the for loop for typically right it it saves you that that entire extra chunk of code extra chunk of processing time yeah yep exactly and so that's something just keep in mind the plus minus those are you know uh element-wise anyway but you know multiplication division and um you know uh exponent is uh something you might need to use the dot for and if you've seen that you might at least make sense to you now yeah it's it's also if you're if you're ever on campus and you get that matlab t-shirt that says x a equals to x dot y x dot backslash y uh that's that that's where it comes from the translation yeah perfect um all right let's try a couple more things just to get a sense of things and then we'll pause for some questions um so one more let's try you know something we might want to actually do is take the mean speed it's b and so it's giving me this error again i just try things i don't think about it first sometimes um but you know the errors should help you and they tell you what to do so it says here these are just integers and doubles what the heck are they talking about they matlab developers i guess um and it looks like yeah sure enough this is an inch 32 and a double so that's just something to keep in mind another common one that you might run into uh the default in matlab is a double uh precision so that's a floating point if you're coming from other languages and uh i mean it's pretty easy to like fix so which one was speed that's an n32 we can make that a double just by calling the you know same kind of way that we did before no problem or we could make the other just in 32 um so it's just something to think about you know again you know sometimes especially when you're working with hardware you know some of the defaults will come in with different precisions so you know hopefully again the errors will help you uh and keep in mind the default is a double so uh we we've we've got a question in the chat uh it's a the question is how do we check if a vectors uh if a vector contains invalid data so you know it's got nan characters or empty spaces and stuff for that that's a good one that's a great one so there's a couple of ways um if if it is specifically to nan you can use is nan um so that would be something like this and you get a logical array back there's also um since nan is specific to numeric data it's not a number so uh there's also is missing so that is more generic for um the you know any data type you know categorical strings anything so that'll encompass a lot of it and actually we'll we'll uh pause on that because i want to show a couple of cool um little app things that you can use to help deal with missing data because there's also really nice things like rm missing um and notice even these little pop-ups that are coming up you know it'll help you out so again if you use matlab like a long time ago like me it was like tilda is nan like totally weird looking code now you can just rm missing or phil missing so great question we'll come back to that one too and the other thing i wanted to point out just the you you kept using the the the tab button to auto complete so that's another cool tip and trick i mean i i use that all the time i i can never remember function names so just hit the tab button it'll give you a list of functions that are available in your system exactly and a lot of times it'll even pop up like in matlab online and using the live editor it'll even just pop up for you and you can type things in and it'll show you what kind of stuff you know what how the function looks and so that's actually we should talk a little bit about the documentation we'll we'll come back to that in a second but um yeah again very very helpful you don't have to just you know start from scratch and you're blinking cursor um one uh let's see anything else i wanted to add um i guess we could we should talk a little bit about plotting so um it's very similar to the uh you know assumptions that we're talking about with array versus matrices and things like that you know if you're plotting something you want these to be the same size otherwise you'll get an error some some plots are different than others we'll talk more about exploring those um but here we're actually plotting you know xy x2 y2 and so it's showing up get as under control here yeah so it's showing up with two plots on it you could also even have passed the like a matrix of that and it would show up with three lines or four lines or however many um you know columns you have so uh another thing you know we'll talk more about the documentation but there are a lot of options here i'll even type in a couple and you can hopefully see some of these options let's see here we go so you can change you know the markers and the line wet things like that uh let's see oh all right pentagram that sounds fun you know so i think again we're kind of going back to uh what's the best way to get started get a doc example and just try stuff honestly and you really get to know things and especially if you have a problem that you want to solve you know i think there's plenty of things that will help you get that get that far and then you can learn along the way and of course we'll share resources in the end for more formal trainings and things like that um a couple other things so uh here it's showing move media and actually i did want to make a matrix we don't have any matrices here so let's uh let's do something like this let's concatenate these so let's say our direction humidity and speed there we go so um because you know again kind of a similar uh point earlier you know these need to be the same size so if you look my measurement or measure vector is now 186 by three so it now has three columns you can click on it that's the other uh nice thing about um you know start getting started with matlab you just just click on things you know and uh it'll help you out we'll talk more about that too so uh now we have all three columns together so uh let's say we wanted to do some calculations you know we showed a little bit on the operators but say we wanted to take the mean of the measurements so it gave us three um answers so it's actually because um of the way that people tend to work in matlab a lot of times in its matrix space many functions work linear algebra wise on the entire matrix and some of these statistical functions we know that you want a summary you know you really just expect one line in the end right and so it'll give you one for each column and then oftentimes you have uh a thing that you can select for the dimension so uh this dim you could say two and that would give you the other direction so if you wanted the mean of all the rows so those are again kind of the fundamental things that you want to keep in mind you'll see you're building up some big equation for your calculations you know these are just uh pointers about how the way uh things work so a question just stop real quick then we've got a couple questions in the chat uh so someone was asking about the about that conversion from in 32 to double that you just did earlier yeah i think you just need a clarification on that sir yeah so um i had uh earlier i had subtracted the um i tried to subtract a double from an integer so um especially in you know this i guess these are things that i don't want to think about as a matlab user sometimes but you know integer math is different like you know you have a different precision you have much uh more limited mathematics that you are able to do on it and a double has the most options i guess i think at least in matlab and so whenever you're working on uh in matlab at least you um need to operate with the same data type so um in our cases let's see if it actually shows up here the sorry i was trying to look at the um size no okay um but the integers are much less uh overhead as far as you know how many bytes that it takes up so a lot of times when you're working with hardware you you tend to want an audio and things like that you tend to want to keep it at a very minimal overhead and like a lower position like or the 32 or at 16. um and then you know double again that's the default so you can convert back and forth either way so i just showed converting one i think so you notice there's in 32 and 16 you can see all of the different options um but basically you just pass the uh you know vector in or array a matrix and then it'll change the type so the type casting um is just basically like any other function double string um you know int whatever single those kinds of things and we we we have another question which actually leads into the next part of our of our of our session today so uh there's a question on how do we work with large csv files at matlab so i think i think that's right on for what we've got coming up next exactly that's perfect actually so um well yeah we'll finish this up i just wanted to work with this script just a little bit longer um just to show one more thing and then we'll talk about file importing and doing that kind of data analysis into the fun stuff i guess um so there's a couple of parts i'm going to run through this just real quick um so we're trying to do a smoothing here we're doing a moving median um if we aren't sure sorry i'm jumping around here so this moving median has a lot of options okay so you have well moving i guess if you were using the smooth function it has different options for your how you want to deal with the smoothing right so um we have now what's called a live editor task so for things like smoothing you know different change point detections uh and a lot of things like synchronizing joining tables uh some of the headaches i think whenever you're working with data so um we could just you know basically take whatever we want here let's speed and if we want to use the moving mean uh we can see what that might do to our data so this is one thing that's really nice you don't have to start with the math or start with the theory you can start with your data or start with your knowledge already and then see what might be appropriate so actually you know i wanted to use moving media and let's make sure that looks good cool um and then you actually have the code so that's one really nice thing we'll probably point out a bunch is that you know a lot of you don't have to actually start with typing things you just you know click on stuff try that try stuff you know look at the tab try these things and then you can you know use the code from there all right so uh last thing i wanted to mention we've been using matlab online this was all just from that one example that i just clicked open um since i had shared it uh or i had sorry i had changed something um i might wanna share this you know so i'm working with connell i might wanna just you know send him what i've got so there's different ways obviously people use github you could go to that extend use different source control and things like that but you can also write from matlab online just take the entire directory and share it so i'll go ahead and do that so i could create a link and i'll do that um all right you can use this link so you should be able to find my example now so i can just copy it go ahead go for it it's awesome um so you copy it send it to my friends send it to like all of youtube like i just said and then you know connor will be able to see the nice thing that i added here with the live task and so we have been using matlab online so let's oh geez don't look at my desktop let's actually go to the matlab desktop so this is you know assuming i had installed it you know that i didn't have to install anything and that's also the most always the most recent version if you have you know an old version or you haven't used it in a long time you know you can always check it out uh there that's the latest and greatest okay um so uh we've got a question talking about deleting single variables from the workspace so how would you how would you delete a single variable from the workspace um great question since you already have that open okay might as well yeah i'll go back here so um one thing um clear is you could it would just if i take clear it'll clear absolutely everything uh you could actually just right click and delete one individually but if you just type clear and then that variable and then you can even keep stringing those along if there are certain ones that'll take care of it um so you know that's that's very handy and then again if i just said clear that would just clear the whole workspace cool so um i also now that i'm in the workspace or in my desktop i wanted to point out i have matlab drive installed so if i wanted to go back to that example i easily could um i think here that's the wrong one all right so i could easily or i could follow my own link i suppose um so uh are there any other questions before we jump ahead or carry on we we've got a couple questions on plotting uh but i think i i think we want to talk about it once we actually have some variables in the workspace because we can sort of show the uh the the plotting tool strip which i love absolutely definitely okay cool awesome so one thing you might notice this is um black and dark which i like uh so this is there are preferences like if you just go to the tool strip you know this is where i say like just click around like just try stuff who knows what's gonna happen um make mistakes it's the way it goes uh but you can change the colors if you prefer a magenta background um like sometimes i do uh right now i'm just going back to the defaults um so i don't hurt your eyes much but you can change a lot of things here even you know the font sizes you know this is where you know a lot of your accessibility kind of things come in and you know any assumptions that you want to do like the display like lots of things can be found here so uh just one other thing i wanted to point out to you while i'm talking about the tool strip you know if you want to we we showed using a doc example we're gonna do the same thing again um but this is where you can find you know connell mentioned about how many people um contribute in the whole world or millions and millions of matlab users so you can find their code and steal it and start with that it's not stealing there's good licenses for it um so if you use add-ons i just clicked from here you can start right away this is also what you would see from the file exchange or the mathworks github many of these are also on the github repo so uh you know you can search around try to find or even hey get started with matlab here are a couple examples i could use and then you just install it right away it just adds it right to your matlab path so you don't have to worry about any of that so another good place and i should probably point out here to you that there's learn matlab and other resources that we were talking about right here just from the tool strap so you know you can take more formal trainings that aren't just me and connell being like wow whatever um but you know we'll also share the link in the chat because there are some really wonderful two hour courses that get you started with matlab a simulink with deep learning machine learning really wonderful all right let's find another example um i think a lot of people in matlab i think well conor will correct me if i'm wrong tend to use time-stamped data right where you have you know either a signal or something like that so let's find an example for that i mean timestamps sort of come up everywhere right signal processing whether you're doing data analysis you're trying to pass through a bunch of big data sets this time stamps everywhere also not now even if you're doing if you're doing iot stuff you know you can get time stamped iot data coming in so there's definitely a lot of scope to work with timestamp definitely yeah i was actually i wanted to use a thinkspeak example because it's really awesome we have a weather station um at the office that we can check the get all the data in the matlab so i just was looking for an example that showed time stamps data are doing something that seems interesting there's a nice little plot and i know it's an example um so if we want to you know i'm actually in the matlab documentation i typed it from um you know the toolbar here and you know this actually is installed with matlab so i have it here i don't even have an internet connection i know sometimes like secret military facilities like don't have internet or whatever so uh you can actually just install the documentation too um and like you saw it before i could just open the live script oh i was working on it earlier okay discard my edits so i'm not cheating and so it actually takes me right to the directory i need to be in so that's something that we should talk about pretty quickly but um we didn't have to worry about it when we were in matlab online we were just where we were um but if you're trying to say you know bring in your csv file like was asked before or you have other kinds of files you need to be in that directory or that directory needs to be on the path basically matlab needs to be able to find it somehow right and so um there's uh here it is there's set path and so that way if you have you know directories that a whole bunch of people are using at work or at school you can just add it there and you won't ever have to worry about like navigating to that directory so um you know you can also obviously you can navigate just by using like normal i don't know windows e things um so let's quickly just run this i was gonna i actually don't even want to run this example i just i like it i think it's a good one we'll put the chat or put a link in the chat but i wanted to use some of the nice functionality for importing and just using the interactive tools so we have a csv file perfect for the chat question and we don't even have to just start by using some import function we can just double click on it and it always opens up on my other window so i'll move it over and you know basically you can see exactly what you would see it in a spreadsheet um kind of form or like a text file lots of options so um especially with excel or spreadsheets you can even use that kind of syntax and then we we showed earlier about just you know basically vectors and matrices for numbers but you notice here there's you know text for the day of the week and the date and so uh it even shows here what type they're going to be brought in as so these are just numbers that'll be a double remember that's the default and then um it's recognizing that this is a repeated string so categorical and datetime so you don't have to worry about all these different details but just know that if you want to keep everything together you could use a table or a timetable or one of those kinds of things that is so you can kind of operate it on it more like a spreadsheet so i'll just click around this is a good time since somebody brought up missing data you know if you had a whole bunch of different things like maybe um you have 9999 and that should be treated with neon you can add different conditions to do that so uh we can just click it'll just import it there was there's a little note here and then i want to point out i think this is one of the most important things about getting started is that you can just click around and try things and then oftentimes generate a script or a function so you don't have to just start from scratch so uh i'll go ahead and do that yeah i i i can see how this will be helpful especially if you're working with multiple different csv files that are at the same time so you just have a script that you know or a function that you call just feed it in that name and it's it's going to do what you wanted to do so that's exactly exactly and so you can call it over and over again and it does all the things that you've selected in the app and so this is the same and we we won't have time to go through all these i think many of our streams and many of our other videos that carl and i are in have other you know machine learning and robotics and things like that that use all of these but this is the best place to start just try stuff click around um so and and as as you mentioned most apps generate code you cannot stress that enough you know so so so typically if you want to start writing code it's almost you it almost makes sense to open up an app and try stuff out you know click click through it and uh just generate the code from there so you know writing stuff exactly and so this is the just to kind of uh clarify you know this is how i would do it if i if i you know want to just start writing the code it'll just bring it right in you know same way um but again much easier especially if you've never seen the data before you can just select all that um and like conor will mention so i'm like losing it already um you know you can just click on stuff right you just try things out um you mentioned about plotting you know maybe we want to just see uh this is bicycle counts for cambridge and boston um maybe we just want to look at this over time and see what the total oh look at this cute nice i didn't see that i just i just downloaded uh 20b it just came out the other day the newest release so it even shows you some nice uh tips for how to do things pretty cool we we we had a question on on on 3d plots and you know so so typically if you if you have your variables in your workspace you can select it like how heather's doing right now and then uh if you go to the plots tab up there you should see all the possible plots uh that you could use with that particular data you know with that piece of data so if it's 3d or whatever you can just go and and try it out in the clock stand up there and this is where i spent like probably seems like i know what i'm doing um once the videos are created but whenever i'm just working with data sets for the first time i just select things and look around and try things and see what happens so uh just since we were talking about 3d you know we have plot three stem three scatter three like these are the kinds of the that's sort of the um pattern and uh well that doesn't look very good but this is how we figured out right um oh maybe that's fun so let's just i wanted to talk about quickly the syntax so it actually every time i select something it actually gives me the code so then if i want to go back i could add this into the script i could um you know just create a new script and just like the plot functions you know if you have three variables you just it's just x y z um so that's really helpful uh the other thing right here if you notice you know maybe this looks confusing if you haven't seen it before um our table is called bicycle counts and it's extracting the data from total so that's what this syntax is the the dot so that's one thing i really want to make sure we get through this uh before we end because like that's something that's really awesome in matlab oh crap i should add a title to my uh plot maybe i just also wanted to mention that you can add you can do all these interactive things here so if you wanted to add um oh geez here we go x labels y labels you know you don't have to just start typing um you know you can just do that so uh don't be afraid click on stuff and it'll show you the syntax so uh because i have this open so i talked about you know that sort of table syntax you know maybe we want to just bring this out if you just click on the variable editor you can do quite a lot so here i want to create a new numeric array and then i'll also show just quickly uh a new table who's again here we go uh just because i wanted to show some of the syntax right so if you look this is um i'm selecting you know multiple columns so this is three and four so those are the columns that i selected before if we had done something let me do something like this there we go so you notice there's i'm getting uh rows one through three and columns three and four so that's the the basic um indexing in matlab is using the number values and if you're using a table you can use the text as well like the column headers um and the colon operator just like we saw with a vector creating vectors that tells it you know use one two and three so if we had just wanted to do uh say you know two and four we can create a vector like that so um at least that that gives you a lot of um you know it's basically row comma column you know you're pretty good shape from there and then if you want all of them you just use the colon object so we we have a question on on managing uh recorded data so do you need sql to do that or can you just pop that into matlab directly um say i i'm guessing listen to talking about accessing data from like a rest you know api or something like that sure yeah um that's a good question so let's see what we get if we look at the dock so i know but i want to show how to show how to do it um so you know depending on what you're trying to do oftentimes web read is the sort of catch-all for um you know any kind of web apis so we can even share some examples there's a couple of uh at least that i have on my github repo um and there's a lot of options for like security information and um things like that uh and this will also you know if you have data in a web page or you know if you just want to scrape the whole thing it's it's again kind of the catch-all for that if there's something that's more specific like um i don't know if i have database toolbox but oh yeah i do so if you have like a database i mean you said sql maybe i'm hearing things wrong because i hear you twice so uh there's also if you have the database toolbox you can also do this in a very interactive way and select the data that you want um but yeah generally web read is a good way to do that and i'll also mention that there are lots of great functionalities on the ad in the file exchange for this stuff because you know certain uh file types are very specific or certain databases you know organized different ways so you you'll often find um you know code that you can use there um i just i want to actually just close the discussion on indexing with one really important uh indexing method so what is this about bicycle counts there it is here we go so let's look at our full table so this is i'm using the live script there was a question about what the difference is between a live script like a dot mlx and dot m um you know you you'll see both uh dot mlx this live script was introduced in 2016 and uh there's a lot of functionality that's just really it integrates the plotting the you know workspace and interactivity uh so you know the uh other editor i guess is the plain text editor we call it so you know that just doesn't uh have these drop downs and things like that no big deal so just stop it right there because we had a question on that um there was a person asking about what is the difference between a dot m and a dot mlx and if there was a if there's a benefit to using one or the other i think just from personal experience my my biggest benefit of using livescripts or the dot mlx is that you can export as html or export as a pdf which uh i i used to do cfd when i was in grad school and to write a bunch of reports with a lot of code um and i spent a lot of time copy pasting plots into a word document or something like that so that if the live script was around at the time i would have you know they would save me six hours per project i guess so so yes if you're if you're looking to create reports or html documentation um the live script is definitely the way to go um oh yeah yeah definitely and see you can see that already i'm just kind of messing around like clicking on things and i think that's the other one for me too it's like it uh keeps track of your plots and your um so it's nice for documentation like connor will mention and even um if you don't want to export it it retains all the stuff that was there so all the plots that you had and all these things and um you can like i just selected you know from this histogram and it actually shows exactly what i was going to show how to you know select data based on the condition so you know again just more helpful kinds of things and the live editor task thing that i showed it just sort of combines all these different environments so um i'll tend to use uh the traditional editor when i'm running kind of a i don't know more hardcore code where i don't really need to share output or i don't want to necessarily like especially deep learning models where i'm running for like six days or something i'm just like just just run and you're the least amount of overhead is possible i don't care you know so i think those are and also if you just prefer like sort of the plain text um environment that's how that yeah there's there's definitely some graphical you know there's some there's some overhead that you are you're sacrificing when you're using the the the rich text editor and stuff that so i i guess it comes down to personal preference but there are definitely a bunch of things where uh the live script is the way to go you know especially if you're trying some stuff out you want to document code uh definitely live scripts are the way to go for that yeah for sure um yeah cool so that's that's uh you know i guess that covers kind of the live script stuff just to close out the indexing conversation this is what i wanted to mention you know if we wanted to get all of the bicycle accounts greater than or equal to 300 18 or 300 that's how we do we just type it right in and then we can copy it change it if we want um logical operators you can find all of this in the doc but it's sort of your traditional you know we want uh this and this you know and we talked about is missing already so um we can share more examples for more on that i just want to check my notes and oh actually yeah we've been using scripts so far i just wanted to comment on functions because we've called functions we're calling a function right here um and in this example it even shows calling a function that is defined by the user so this is a great one i think this gives you a really good idea of all the different syntax and the different options especially with missing or messy data like we said and um somewhere i will find what i was trying to say all right okay here we go we're getting we're reaching the end so maybe i'm just completely losing it i thought there was a helper function in this one so maybe not um but if we wanted to just create a function that's okay we don't need a helper function um we could just say new function because i just wanted to point out with our script we have everything in our workspace um we might not want that we might not want to have every single step we might just want to return one output and have it operate kind of like the sign function we want somebody else to just call it like that so uh this is basically you know the syntax so whatever you want to do happens here this is the outputs and the inputs just like you've called it and then you have your function keyboard so not too big of a deal and if you're you know more if you're coming from other languages you can have you know it's a fully uh fleshed out class system object system there's a lot of great functionality there um so just wanted to point out the different modes of operation basically um all right whoo let's see anything else that we didn't talk about i i think i think we've covered most of what we had in uh in mind it was it was good we had some we had some technical difficulties and stuff but i think we i think we got through that pretty well um there is one question i've seen i've seen a lot of people commenting in the chat on on us doing a simulink live stream so yes we will we we will do a simulink live stream in the future um but actually it's a couple weeks i think um we'll get back to you on the date we'll make sure we get that out to you so that's yeah that's one of the great well you're you you talk about that yeah and then and the there there's another question and asking on what is the difference between matlab and civility i think basically the the basic difference is matlab is a textual programming language so you're writing code you know like you would in in another language but as in simulink you're doing the same thing but using something called as block diagrams so if you're a control systems engineer control systems engineers like um you know we we we think sort of in block diagrams because everything is you know everything is a block diagram from sometimes we start studying um so so simulink works um in blocked items you can see how this pulled up uh pulled up simulink on the screen um you essentially can can do most of the same things that you can do in matlab matlab has a little has a little more functionality that than simulink just because of the of the inherent nature but but the way simulink works is simulink is used for um for simulations so you you can you feed in a differential equation and siblings got these very robust um numerical solvers that can again one of my favorite quotes on simulink is something that a customer said he said um simulink eats differential equations for breakfast which is which is my favorite quote of all time uh but but yeah it's essentially you you use whenever you're running a simulation you're solving some sort of differential equation and siblings uh got these solvers kind of like ode45 is in matlab there is an od45 in the simulink as well but there are a lot more um so we definitely stick it on for the simulink uh for simulating one ramp in the next few weeks definitely subscribe to the channel hit that subscribe button but yeah i mean that's that's the best way to keep up to date and we're gonna have um ed this he's a really big simulink expert um and you know we'll we'll talk about all those questions and of course the documentation even you saw the start page has a whole bunch of examples this was one i wrote is which is obviously not very um sophisticated but i like blinking um leds so what can i say um that's awesome so i guess is there any other questions before we close things out i think um i mean i definitely would highly again we've talked just about some of the fundamentals here but the uh trainings um that you know you can see well here um you know these auto ramps are free again you don't have to have a matlab license or access at all like just you know go for it and you can learn deep learning machine learning and get a sense it's just like we saw basically using matlab online in the back end um and then there's a lot more thorough you know classes with certifications and things like that if you really want to you know go to town but really the best way you know look at the doc rtfm um and you know check out videos subscribe you know try things and uh don't be afraid click on stuff get get mistakes uh make mistakes get the errors and the errors will help you hopefully yeah and also one last thing you know we kind of hinted at the community but there's so many wonderful um if you have questions obviously you can ask us or we can reach out on social media um but you know this is a great way you know if you have questions like some of us you know when we're bored at work we'll just go on to matlab answers and you know uh you can find a lot here and file exchange we kind of showed um there's the whole world is here to help you uh get started or carry on with your skills so i guess yeah i guess we'll um we'll end it there don't be afraid to reach out we have our social media info here and again subscribe you know interact here in the comments um you know we'll keep in touch on any questions you have and we'll be back in a couple of weeks with simulink and more so you know keep up to date thank you so much this is awesome and i really appreciate sticking through uh the early issues uh technical difficulties that's life right it wouldn't be a live stream if there wasn't something going on awesome thank you very much and we'll see you again see you again soon you
Info
Channel: MATLAB
Views: 12,081
Rating: undefined out of 5
Keywords: work from home live, matlab, simulink, mathworks, matlab tutorial, using matlab remotely, working from home matlab, time series data in matlab, how to plot time series data in matlab, time-series, time-series data
Id: hYSGTdbO-5g
Channel Id: undefined
Length: 50min 16sec (3016 seconds)
Published: Thu Sep 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.