How to create a plot with a range in your x-axis
1 view (last 30 days)
Show older comments
Create a vector 't' which consists of 100 numbers uniformly spread between 0.01 and 1. Also create a vector 'f' which includes the corresponding 100 values of the function 't2 + 3t – 15'. Create a figure with four subplots arranged as 1 row and 4 columns. The first subplot should contain the function for 't' ranging from 0.01 to 0.25, the second subplot should contain the function for 't' ranging from 0.26 to 0.5, the third subplot should contain the function for 't' from 0.51 to 0.75, and the fourth subplot should contain the function for 't' from 0.76 to 1. Make sure that the horizontal axis of each subplot shows the corresponding range of 't'. Include the code and the generated figure in your document.
Here is what I have done so far % Homework 3 Problem_5 clear all; close all; clc;
t=[.01:.01:1]; f=(t.^2+3*t-15);
figure(1), subplot(1,4,1),plot(t(.01,.01:.25),f)
Some help please! thank you
0 Comments
Answers (1)
Steven Lord
on 2 Oct 2017
There's no such thing as element 0.01 of an array in MATLAB. Your attempt was a good try, but it won't work. I suspect the purpose of this homework assignment is to familiarize you with logical indexing. You can use logical indexing to extract the appropriate pieces of t and f to plot in each subplot. Hint: since t and f are the same size, a logical "mask" suitable for use on one of those variables will also work for the other.
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!