フィルターのクリア

creating a figure that is a segment of another

3 ビュー (過去 30 日間)
SonOfAFather
SonOfAFather 2012 年 8 月 29 日
i have a script that gives my figure(1) that graphs a cos wave over 5 sec then i need to section out the first second and have it display in figure(2). when i run my script i get the first figure and the second only displays the x,y cooridinates.
i think i have a problem in the way i sectioned the original vector.
my script looks like this:
clear;
clc;
close all;
% create vector of time values
t = 0.0 : 0.01 : 5.0;
% evaluate function at time points
f = 53*cos(104*pi*t).*exp(-1.35*t);
% plot t vs f(t)
figure(1)
plot(t,f);
xlabel('t(sec)');
ylabel('f(t)');
%reindex t to exclude the last four seconds
t = 0.0 : 0.01 : 5;
%plot t vs f(t)
figure(2)
plot(t,f(t));
xlabel('t(sec)');
ylabel('f(t)');

採用された回答

Sven
Sven 2012 年 8 月 29 日
編集済み: Sven 2012 年 8 月 30 日
I see a few problems:
Your f variable is still based on the original vector of t. You need to run:
f = 53*cos(104*pi*t).*exp(-1.35*t);
again, after you set your new t
Also, you have set t to be the same vector (ie, t = 0.0 : 0.01 : 5; ). I don't think you wanted this.
Finally, in the second figure you are calling:
plot(t,f(t));
but t is still a vector of times, not a vector of indices.
Perhaps you meant the following:
% First figure
t = 0.0 : 0.01 : 5.0;
f = 53*cos(104*pi*t).*exp(-1.35*t);
figure
plot(t,f);
xlabel('t(sec)');
ylabel('f(t)');
% Second figure, using only first 1/5th of t, f
idxs = 1:round(length(t)/5);
figure
plot(t(idxs),f(idxs));
xlabel('t(sec)');
ylabel('f(t)');
By the way, have you tried instead just:
set(gca,'xlim',[0 1])
You can run this after the first plot, and it will "zoom in" on only the first portion from 0 to 1 along the x axis. The rest will be excluded from view.
  1 件のコメント
SonOfAFather
SonOfAFather 2012 年 8 月 30 日
thank you the "idx( = 1:round(length(t)/5);" is what i had forgotten about.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by