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 9133939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:34:31+00:00 2026-06-17T08:34:31+00:00

Having some trouble declaring functions within my script: %Read the raw audio data refData

  • 0

Having some trouble declaring functions within my script:

%Read the raw audio data

refData = wavread('file1.wav');
userData = wavread('file2.wav'); 

% I want to continue writing my "main" function here, and call the below functions

%%%%%%%%%%%%%
% Functions %
%%%%%%%%%%%%%

%Vector x
function preEmphasis(x)
    alpha = 0.95;
    len = length(x);
    for i=1:len
        x_i = x(i);
        x_iMinus1 = x(i-1);
        x(i) = x_i - alpha*x_iMinus1;
    end
end

%Vector x
function normalization(x)
    maxVal = max(abs(x));
    x = x / maxVal;
end

%Vector x; numFrames, frameSize: integers; stepSize: percentage (float, 0.2 -> 0.5 for example)
function Ymatrix = createYmatrix(x, numFrames, frameSize, stepSize)
        Ymatrix = zeros(numFrames, frameSize);
        for i=1:numFrames
            for j=1:frameSize
                Ymatrix(i,j) = x(stepSize*i + j);
            end
        end
end

The words “function” and “end” are highlighted in red as “parse errors”. How can I fix this? Thanks.

  • 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-17T08:34:32+00:00Added an answer on June 17, 2026 at 8:34 am

    You can’t declare functions within your main script. You have to create an external m-file and implement your function inside it, like it says in the official documentation:

    Any function that is not anonymous must be defined within a file.

    (just to be clear, a script does not accept input arguments or return output arguments).

    However, you can have local functions declared inside a function m-file.
    Read more about function declarations in the official documentation.

    EDIT: You can Refer to @natan’s answer if you’re looking for a way to avoid function m-files altogether. He implemented your functions as anonymous functions, which can be declared inside the script file. Good luck!

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

Sidebar

Related Questions

Im having some trouble looping through some xml data. The xml file is structured
I'm having some trouble in declaring a STL Set of pointers to class instances.
Having some trouble getting BIRT to allow me to create a Data Set with
Having some trouble refreshing the image, i have a script running in the background
Having some trouble understanding variable scope within a class structure. I want to create
I having some trouble with an APCS assignment. The program is supposed to read
Having some trouble with R's garbage collection, when passing objects to C++. We have
Having some trouble getting a screenscraper webservice up and running on a weblogic 10.3.3
Having some trouble with what should be a very simple scenario. For example purposes,
Am having some trouble with the SkyDrive download process and hoping you can help

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.