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

1 回表示 (過去 30 日間)
Tony Nguyen
Tony Nguyen 2017 年 10 月 2 日
コメント済み: Tony Nguyen 2017 年 10 月 2 日
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

回答 (1 件)

Steven Lord
Steven Lord 2017 年 10 月 2 日
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 件のコメント
Tony Nguyen
Tony Nguyen 2017 年 10 月 2 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by