Variable is changing when being read into a function
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I am passing a number into a function, but when it is read into the function it seems to have been changed. so something like this:
...
x = somefunction(5);
function [x] = somefunction(num)
whos num ...
...
and it returns:
Name Size Bytes Class Attributes
num 1x2361 18888 double
This is causing the whole program to crash. If I say "clear num" at the beginning of the function and then reset it within the function, it works fine. I feel like there is an obvious answer of what is happening wrong here, but I cannot find it. Thanks for any help.
1 Comment
per isakson
on 20 Jan 2012
MATLAB doesn't behave like that. You provide too little information.
Answers (1)
Andreas Goser
on 20 Jan 2012
Indeed, there is not enough information for a real answer. Some ideas:
1. Somewhere between
function [x] = somefunction(num)
and
whos num ...
num is altered.
2. num is somehow used a global or similar and there are conflicts. Try
which num -all
to find out more.
3. The size of 1x2361 should give you a hint. What in your application has this size and maybe this leads you to the problem.
If this all fails - reproducible code examples will help.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!