필터 지우기
필터 지우기

Matlab doesn't give the same result if all functions put in one file

조회 수: 2 (최근 30일)
farzad
farzad 2020년 3월 31일
댓글: Walter Roberson 2020년 4월 2일
Hi all
I have one main file that runs a function (F1) that this F1 calls a second function F2 inside it. I need to put all of these functions into one single file to use them in one app.
but when I tried to run this single app, I see, that despite giving no error, just the solution is different that does not lead to the same result. true that I need to make some variables global that I have actually done.
I even copied the non working series of functions from the app back into an mfile code and there !! PAM !!! it works !! It seems that using global variables, the values are not passed correctly somehow but I don't know how ! and why
the function F1, calls the F2 in a loop and in each loop it should pass a value like :
for i=1:rows
[result] = functionF2(l1,u1 , time(i,:))
end
Since the code is huge, I CAN'T share it here. BUT I wanted to know if there is any way to know the reason this kind of malfunctioning happens. the code runs smoothly when I have multiple files, but I can't find where the code works different, specially in second function F2 when I put all of them together. Any hints without seeing the code ?
  댓글 수: 13
farzad
farzad 2020년 4월 2일
Thank you so much Stephen and Walter ! I solved it ! It was a for loop counter with a common name with another counter inside the second function being called inside the First function loop.
therefore the counter color in app had become blue and was warning me that this counter is changing its value.
strange that this same code did not experience any error and gave the right result in matlab base
Walter Roberson
Walter Roberson 2020년 4월 2일
If it became blue then you probably accidentally ended up with nested functions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by