Variable is changing when being read into a function

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

MATLAB doesn't behave like that. You provide too little information.

답변 (1개)

Andreas Goser
Andreas Goser 2012년 1월 20일
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.

이 질문은 마감되었습니다.

질문:

2012년 1월 20일

마감:

2021년 8월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by