Tips to get help with MATLAB Writing Services in 2023
How to create and run a basic MATLAB program:
So if we open up MATLAB Writing Services we’ll see a big panel in the middle this is called the command window the command. The window is used to execute commands one by one I’ll show you what I mean we can create a vector X that goes from 1 to 10 and when I hit enter this vector is created. In our workspace or I can create a vector Y which is equal to the square root of x and when I hit enter this vector is also created or I can even create a plot from these two vectors.
I hit enter this figure pops up on the front of my screen so as we can see the command window is great if you want to execute commands line by line but. What if you want to execute multiple commands at a time well you can do this by creating a live script let’s close out of this figure and, I’ll show you two ways to accomplish this the first way is to click new and then. Live script and when you do this you’ll see the live editor window pop up on top of the command window here you can type multiple.
Commands without executing them right away:
Commands without executing them right away but let’s say you already typed a bunch of code in the command window and you want to preserve it for when you create yours. Live script how do you do that first go to your command history and highlight all the commands you want to include in your script I’ll pick the 3 that we just typed then right click. With these commands and hit create the live script you’ll notice that just like before the live editor pops up on top of the command window but this time it already has the commands that we highlighted now to run this script I first have to save my file by going to save.
Giving it a relevant name:
Giving it a relevant name then I’ll go to the top here where it says run all and hit that button when I do this all of the commands in the script are executed we can see in our workspace that 2 vector X&Y was created in MATLAB Writing Services and right next to our code. We see the figure that was generated from the plot command based on your preference you can choose whether to have these outputs on the side of your code or in. Line with your code these two buttons up here will let you switch between the modes I’ll switch to in line mode so you can see what it looks like okay so the program we wrote so far is pretty simple I want to go
A few tasks that you may use while writing something:
Through a few tasks that you may use while writing something more complex task number one is adding comments will help make your code understandable typically they’ll describe. What your code is doing you can add a comment by typing a percent sign and then typing your comment like this another way to organize your code is to add sections to it. What do I mean by this well when using live scripts in MATLAB Writing Servicesyou don’t have to run the entire file you have the option to run your code section by section sections will also visually split up your code making it easier to read and comprehend. To add a section I’ll type two percent signs followed by a space and the name of my section when I hit enter .
Visual break in the code that separates the section:
A visual break in the code that separates the section I just created let’s put a couple of commands here to show you how to run a specific section of code. I’ll create a vector X with values 1 to 100 and, I’ll create another vector Y with values 101 to 200 and then. I’ll plot X comma Y and make the plot red now instead of hitting run all like, I did before I’ll highlight the section. I want to run and hit run section we can see the figure that corresponds to the section pop-up next to the code we just type and if we click on one of these plot commands. We can see that the corresponding figure is highlighted this is a really useful feature for navigating through your results.
Matrix that we already created:
Matrix that we already created in MATLAB Writing Services for example let’s look at one of the vectors we created earlier why if we open the variable editor we can see that each element in Y takes on a different value. Now let’s say we want to access the fifth element in this vector we can type Y and then in parentheses five to get this number or if we want the seventh element. We’ll type Y parentheses seven close parentheses here’s some practical examples of tasks .
Do with indexing we can create a new variable a which is equal to the fifth element in Y a equals y of five now our workspace shows that a is equal to the same value as Y of five or, We can change the fifth element of Y to be 100. We’ll type Y of five equals 100 enter and we can see that after executing this command the fifth value of Y has changed okay one last example let’s say we want to change the first five values of Y to be the numbers six through.
Values of Y have changed accordingly:
We can type Y of 1 colon 5 equals and then in square brackets 6 7 8 9 10 when we hit enter we can see that the first 5 values of Y have changed accordingly so this covers some of the basics of indexing and the next thing. I want to talk about is something called MATLAB Writing Services the if-else statement you’ll use an if-else statement if you want to execute a set of commands only if a certain expression is true this will be more clear with an example let’s start by writing a statement that takes in a user input the line of code. I just typed is going to ask for input from the user and convert their answer to a string before proceeding.
If-else statement that determines:
The user in as a string now that we have our user input will create an if-else statement that determines what to do based on that user’s input so, I’ll type it all out and then we can go through it. Starting from MATLAB Writing Services the top if the user types Y then the first expression user in equals Y is true and will display hurray but if the user does not type Y and types n instead then the second expression is true. And will display oh man finally if the user types anything that’s not Y or n will display. Please reread the directions so let’s actually run the program for the three cases I’ll hit run section and answer the question with Y for yes the live editor executes the code and the if section and displays hurray.
You may also read 7 Key Considerations Before Hiring Assignment Help.