![]() ![]() So this is a very simple example of a technique that is used all the time in MATLAB where you will just take the results and store them in a matrix for easy manipulation and use later. ![]() Now that it's done what we can do is come in here and say Plot (y), and we can see that on the graph here. And each time we keep adding another column to this. And what we'll see by scrolling up through the Command Window here is that at first, we have Y is equal to a 1 by 1, then a 1 by 2, 1 by 3. So every time through the loop now this statement is going to read Y element 1 or 2, or 3, or 4, is going to equal to the same thing it did before. So what we can do is come in here and say I want to make Y into a vector. ![]() That isn't going to do very well if we want to plot this data. Now what if we wanted to plot those? Well, every time through this loop we have overwritten the value of Y so we lost, like for instance, 9.528 when we generated 10.857. And we can see we've gone through this loop 10 times and gotten different values of Y. I'm going to run it by hitting F5, which means save and run the current file. So I want to actually see the results of this. So we're going to just have a random number generated-somewhere between 0 and 1-and add it to the current value of I, and end. Now inside of this loop what we're going to do is say Y is equal to I plus rand. What we're going to do is say for I is equal 1 : 10, meaning that we're going to count from 1 to 10. * Method to return a string with information about this picture.In today's video on MATLAB basics, we're going to show how to store the results of a calculation inside of a vector, which is a special case of a matrix. * Constructor that takes a buffered image * Constructor that takes a picture and creates a copy of that picture let the parent class handle this width and height * height the height of the desired picture * Constructor that takes the height and width let the parent class handle this fileName * fileName the name of the file to create the picture from * Constructor that takes a file name and creates the picture * child constructors always call a parent constructor ![]() * not needed but use it to show students the implicit call to super() ** Constructor that takes no arguments */ * Barbara Ericson class Picture extends SimplePicture * allows the student to add functionality to the Picture class. This class inherits from SimplePicture and 2) write a method called switchColors() that replaces red values (using p.setRed) with green or blue values (using p.getGreen(), etc.) to change the colors around. Picture Lab: 1) write a method called keepOnlyBlue() that keeps only the blue values by setting the red and green values to zero. You can test the methods in the active code below or in this Replit Swing project or this alternative Replit project by teacher Jason Stark from LA (click output.jpg to see the result) or your own IDE to see what it does. You will need to use the getRed, getGreen, getBlue to get the RGB values of the pixel and then swap them around by using the setRed, setGreen, setBlue methods and giving them different color values from the get methods as arguments. Then, write a method called switchColors that swaps the red pixels with green pixels or blue pixels to change the colors around. Now, write a similar method called keepOnlyBlue that visits every pixel and sets the red and green values to zero but does not change the blue ones. It uses nested loops to visit each pixel in a photo which has a color with red, green, and blue values, and it sets all the blue values to 0. Scroll down to the bottom of the following code and take a look at the zeroBlue method. In this challenge, you will do a part of the Picture Lab to modify the pixels of a digital photo. Click on the CodeLens button to trace through the code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |