Variable is changing when being read into a function
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentario
per isakson
el 20 de En. de 2012
MATLAB doesn't behave like that. You provide too little information.
Respuestas (1)
Andreas Goser
el 20 de En. de 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.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!