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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:30:04+00:00 2026-06-11T01:30:04+00:00

Im a new MATLAB user. Trying to initialize y to the calculated value in

  • 0

Im a new MATLAB user. Trying to initialize y to the calculated value in the if statement. However, when I try to plot y it says y not defined

function [y,xmax] = Alaw(x,A,ymax)

if nargin<3, ymax=1; end
if nargin<2, A=87.6; end


xmax=max(abs(x)); 

    temp = ymax/A;
if ((x > 0) & ( x < temp ))
    y = (A * abs(x)) ./ (1 + log(A) ).*sign(x);
end    

if (x > temp)
    y = ymax*( 1 + log(A*abs(x/ymax)) )./( 1+log(A) ).*sign(x);
end


 fprintf('Plotting Data ...\n');
 hold on;
 figure;
 plot(y);
 xlabel('x-axis');
 ylabel('y-axis');
 title('  A LAW ');

 pause;
 fprintf('Writing the audio file ...\n');
 wavwrite(y, 22050, 'Alaw.wav');


 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-11T01:30:05+00:00Added an answer on June 11, 2026 at 1:30 am

    If x is smaller than or equal to zero, or if x equals temp, neither of the if-statements is true, and thus, y never gets defined. You may want to re-write the logic with if..elseif..else to ensure that y gets assigned in every case:

    if ((x > 0) & ( x < temp ))
        y = (A * abs(x)) ./ (1 + log(A) ).*sign(x);
    elseif (x > temp)
        y = ymax*( 1 + log(A*abs(x/ymax)) )./( 1+log(A) ).*sign(x);
    else
        y = NaN(size(x)); % no valid y; this won't plot anything, but won't error
    end
    

    Note that x>0 can lead to unexpected results when x is an array. Use all or any to make sure that the condition is satisfied if either all or any of the elements of x satisfy the condition, respectively.

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

Sidebar

Related Questions

I'm new to Matlab and I'm trying to write custom function in matlab that
I'm very new to matlab and am more of an ArcGIS user but I'd
In MATLAB, when you click File -> New -> Function M-File, you get a
I'm trying to ask the user for a value of some variable, but at
I am new to MATLAB and I am trying to built a voice morphing
I am new to MATLAB, and I can't fathom this from the documentation. function
I'm very new to MATLAB and I was trying to display a real time
I am very new to matlab and trying to solve portfolio optimization problem (minimizing
I am new matlab user. Now, I'am doing my work by using matlab software.
I'm new to MATLAB and I'm having problems plotting these two equations. I'm trying

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.