Introduction
The purpose of this lab activity is to help us become familiar with MATLAB as programming language. Specifically in this activity we focused on using the MATLAB IDE, using variables of different types such as arrays and matrices. Additionally, we went over the basic arithmetic operations that we can perform on these data types. Overall, this lab provides a strong base and experience with a skill that will prove invaluable in future labs and activities in this course.
Procedures
- Why do we clear the command window and workspace at the beginning of a script?
- The main reason why it is important to clear the command window and workspace is because we do not want variables and console history from previous scripts that have run to effect our current work, whatever it may be. For example, if you run scripts with overlapping variable names then you can accidentally initialize variables with unexpected values.
- Why would we use variables instead of just using the numbers, which is called hard-coding?
- This is dangerous because it makes our code very hard to change later on. For example, if you have code that references a certain values often and you have that value hard coded over and over again, then it can take a lot of time to replace that value every as opposed to simply changing a variable name.
- What system would you use to organize your variables and remember what each means?
- The system I prefer to use works as follows. I use the name of the larger object the variable is describing an attribute of then add the name of what the variable holds, all using camel case.
- What are the benefits to using the array indexing approach?
- Using array indexing in MATLAB provides efficient access and manipulation of data, allowing for concise and readable code when working with large datasets or matrices. Additionally, MATLAB’s built-in functions often leverage array indexing for optimized computational speed.
- In your opinion, would the automatically generated variable ans or a user-defined variable be
more useful in writing scripts?- I think a user defined variable would be easier for two reasons. Firstly, it would make it easier to reference later on in the code and secondly it helps to improve the readability of the code.
Conclution
Overall, I enjoyed this lab a lot. I like getting used to using MATLAB and I also enjoyed creating an ePortfolio for the first time. I think it was challenging figuring out how to do some of the different tasks in the lab in multiple different ways as the procedure called for. Overall, I think this a good lab that future students in signals and systems will enjoy and find very useful as an introduction to this tool.
Leave a Reply