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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:40:05+00:00 2026-06-15T08:40:05+00:00

So I got this function: function M = getA(X) global h; QPL96 = h;

  • 0

So I got this function:

function M = getA(X)
global h;
QPL96 =  h;
M = QPL96;
endfunction

Now:

octave:115> h
h =  0.10000
octave:116> getA(X)
ans = [](0x0)

Isn’t that strange?
Works as long as there isn’t an expression involving h. Otherwise returns that garbage.
Why can’t I do this? Must I work around it by making h an argument?

  • 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-15T08:40:07+00:00Added an answer on June 15, 2026 at 8:40 am

    You’ll have to declare h as global everywhere you want to use the “global” h, and that includes your main body. So type global h at the prompt and you’ll be fine. See the documentation. The following works fine for me:

    octave> function M = getA(X)
    > global h;
    > M = h;
    > endfunction
    octave> h = 0.01
    h =  0.0010000
    octave> getA
    ans = [](0x0)
    octave> global h
    octave> h
    h = [](0x0)
    octave> h = 0.01
    h =  0.010000
    octave> h
    h =  0.010000
    octave> getA
    ans =  0.010000
    

    But really, you shouldn’t use global variables, that’s really bad practice. Pass the variable as argument. If you find yourself passing the same group of variables, pass a struct, but still don’t use global variables.

    EDIT: this is the same question.

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

Sidebar

Related Questions

I got this function to split string but it's giving the spited string in
In the end, I got this function. I don't know whether it's normal or
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I've got this simple function which displays a message to the user. If I
I've got this jQuery function: function phpmail(){ $.post('mail.php',{name:$(#name).val()}, function(out){ alert(out); }); } and this
I got this from for a login form tutorial: function sanitize($securitystring) { $securitystring =
I've got this code in the InitInstance function of a class that extends WinApp:
I've got this script on my website : $(document).ready(function() { function filterPath(string) { return
So i got this snippet of code: $(document).ready(function () { var replacementDoneIn = $(body).html();

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.