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
per isakson
2012년 1월 20일
MATLAB doesn't behave like that. You provide too little information.
답변 (1개)
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.
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!