Variable is changing when being read into a function
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
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 commentaire
per isakson
le 20 Jan 2012
MATLAB doesn't behave like that. You provide too little information.
Réponses (1)
Andreas Goser
le 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.
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!