Ploting & Inner Functions Flashcards
How can we graph an XY relationship?
By using the command:
plot(x, y)
How can we get the maximum or minimum value of an array?
max(array) or min(array?
How can I get help for finding functions?
Click Fx on the command line and use the search bar for finding whatever function you want.
How do we get information about what a function does?
Use the command “help”. For instance:
help min —> will tell you everything you need you need to know about the function min.
Another way to obtain documentation from the original source?
Use the following:
doc function —> This will open the official documentation from matlab
How do we get the index where the max or min is located?
[maxVal, I] = max(y)
How do we define functions in the same way as we do in math? As in, with the argument and all?
We use “anonymous functions” like this:
y = @(x) (function def)
y = @(x) (x+2).^2
How to create a plotting environment?
Use figure(#number)
How can I plot several graphs on a same figure?
By plotting and then holding on, like this:
plot(x,y)
hold on
plot(x,z)
How to provide labels to the axis?
xlabel(“name of the label”)
ylabel(“name of the label”)
How can we add titles to graphs?
Using title(“name”) command
Activate grids?
Grid on
How can we add legends?
With the legend(“name”) command
How can I limit the axes?
xlim([a b])
ylimit([a b])
How can I fill up discrete points so the can look continuous?
Put markers before the color, like for instance:
plot(x, y, “- - g*”)
It will add dashes to fill up
How can I plot different images in a single figure but in individual plots?
Use the subplot command:
figure(1)
subplot(m, n, #position)
How does matlab returns true or false statements?
With 1 for true and 0 for false.
How can we perform logical comparisons between elements from an array/matrix with a single element?
Matlab makes it easier by simply comparing the array/matrix with that element:
A > 2
Here, if A is an array/matrix, it will check if every element is greater than 2 and it will return an array of the same size of A with 0s and 1s.
How can I add or multiply all the elements of an array?
Using sum(A) or prod(A)