How to execute saved function file

조회 수: 1 (최근 30일)
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 20일
댓글: Hayatullahi Adeyemo 2017년 11월 20일
I read a function file and save it in a cell array. I modified the content of the cell array that contains each line of the function. I then saved it in another function file. Can I immediately execute the newly saved [function] file given some input values. I tried it and intend to save the output of the function in a matrix, it seems like I get same result always (which is wrong) based on the content of the matrix after executing a loop. Please advise me on what to do to have normal and accurate result on executing the immediately written function file.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 20일
After you save a function to a .m file, you should "clear" the function name to remove any cached code of the function.
  댓글 수: 1
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 20일
It worked! I have spent months trying to fix this bug. I kept on getting results for iterations 2 and above as if the variable or the file is sticking to previous contents. Thanks Walter Roberson.

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

추가 답변 (1개)

ES
ES 2017년 11월 20일
Do you save it in a different file name (and function name)?
If NO, then its highly likely that your old file gets executed (especially if its higher on the path or in the current directory).
  댓글 수: 1
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 20일
Yes, I save it in a different file name. But the function name still carries the old file name. For example, the old file name is sumOfRoots.m which contains a function with name sumOfRoots(inputs). Now the new file is called (e.g. newFile.m) but with the function name sumOfRoots(inputs). What I want is actually to be able to execute the new file and see the effect of the changes I made to the original file. Thanks @J Smith.

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by