Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9295757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:40:55+00:00 2026-06-18T21:40:55+00:00

% Code slightly modified from Signals and Systems by Lathi MS2P4 pg 232. How

  • 0

% Code slightly modified from Signals and Systems by Lathi MS2P4 pg 232.

How can I make this code a function? So that I can just “call” it to use it. Instead of pasting this whole thing over and over. This is just a convolution animation of two functions.

figure(1) % Create figure window and make visible on screen 
x = @(t) cos(2*pi*3*t).* u(t);
h = @(t) u(t)-u(t-1);
dtau = 0.005;
tau = -1:dtau:4;
ti = 0;
tvec = -1:0.1:5;
y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
for t = tvec,
    ti = ti + 1; % Time index
    xh = x(t-tau).*h(tau);
    lxh = length(xh);
    y(ti) = sum(xh.*dtau); % Trapezoidal approximation of integral
    subplot(2,1,1)
    plot(tau,h(tau),'k-',tau,x(t-tau),'k--',t,0,'ok')
    axis([tau(1) tau(end) -2.0 2.5])
    patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
        [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
        [0.8 0.8 0.8],'edgecolor','none')
    xlabel('\tau')
    legend('h(\tau)','x(t-\tau)','t','h(\tau)x(t-\tau)')
    c = get(gca,'children');
    set(gca,'children',[c(2);c(3);c(4);c(1)]);
    subplot(2,1,2)
    plot(tvec,y,'k',tvec(ti),y(ti),'ok')
    xlabel('t')
    ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau')
    axis([tau(1) tau(end) -1.0 2.0])
    grid
    drawnow
%   pause
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:40:56+00:00Added an answer on June 18, 2026 at 9:40 pm

    You can use Matlab’s function , as described here

    So, you have to write on the top “function yourFunctionName” and then you can call it using its name, yourFunctionName in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run slightly modified code from the Qt fluidLauncher demo that
I've taken code from the MSDN page on Matrix Filters and modified it slightly.
I have the following code slightly modified from the Visual Studio 2010 css template.
Here is some code I modified from this nifty site : http://jsfiddle.net/Ajhka/ I have
I'm using the following code (which is a sample from the MSDN slightly modified)
Below is a slightly modified code from one good example how to copy values
Answer, slightly modified from marked answer: var eoc = easeOutCirc,mNSS = 'metrsoNavSpanSelected'; $('.metroNavSpan').click(function(){ var
From ICanHaz example (slightly modified version of this: http://icanhazjs.com/ ): The template: <script id=user
I am using a slightly modified version of this code . to create a
I am using generic code (from the iOS Fireworks demo) in a slightly changed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.