how can i plot the function m(t) in matalb?

回答 (2 件)

Akira Agata
Akira Agata 2017 年 11 月 12 日

0 投票

How about this?
% Calculate m(t) between time = 0~0.08
time = 0:0.001:0.08;
y = arrayfun(@mt, time);
% Plot m(t)
figure
plot(time,y)
% Function m(t)
function y = mt(time)
t = mod(time,0.04);
if t < 0.01
y = -4 + (8/0.01)*t;
elseif t < 0.02
y = 4;
else
y = 4 + (-8/0.02)*(t-0.02);
end
end

2 件のコメント

Greg Heath
Greg Heath 2017 年 11 月 12 日
Copying and pasting your answer yields the error message
Error using arrayfun
Undefined function or variable 'mt'.
Hope this helps.
Greg
Akira Agata
Akira Agata 2017 年 11 月 12 日
Hi Greg-san,
Please save as a script file, and run it. Then, the following plot appears.

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

Greg Heath
Greg Heath 2017 年 11 月 12 日

0 投票

% Save the file mt. Then display it
>> close all, clear all, clc
>> type mt
function y = mt(time)
t = mod(time,0.04)
if t < 0.01
y = -4 + (8/0.01)*t;
elseif t < 0.02
y = 4;
else
y = 4 + (-8/0.02)*(t-0.02);
end
end
% Now,use it
>> time = 0:0.001:0.08; y = mt(time);
>> figure, plot(time,y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Hope this helps.
Thank you for formally accepting my answer
Greg

カテゴリ

ヘルプ センター および File ExchangeMATLAB Mobile についてさらに検索

タグ

質問済み:

2017 年 11 月 11 日

回答済み:

2017 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by