How to create a plot with a range in your x-axis

1 Ansicht (letzte 30 Tage)
Tony Nguyen
Tony Nguyen am 2 Okt. 2017
Kommentiert: Tony Nguyen am 2 Okt. 2017
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

Antworten (1)

Steven Lord
Steven Lord am 2 Okt. 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.
  1 Kommentar
Tony Nguyen
Tony Nguyen am 2 Okt. 2017
I've got it!
% 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,f) axis([0.01 0.25 -15 -10])
subplot(1,4,2),plot(t,f) axis([0.26 0.50 -15 -10])
subplot(1,4,3),plot(t,f) axis([0.51 0.75 -15 -10])
subplot(1,4,4),plot(t,f) axis([0.76 1 -15 -10])
hehehe thanks

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by