필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

after writing my script and running it, it is only returning the file name with no error meaage. What is the problem here?

조회 수: 1 (최근 30일)
I wrote a script to solve an integral and saved it under CP1. After clicking run, it only returns the file name "CP1" with out any kind of error message. What is the problem here?
wt = [1,4,2,4,2,4,1];
L = 3;
amp = 1;
type = 1;
n = 5;
h = L/(n-1);
wt = wt*(h/3);
Int = 0;
for i=1;n;
x = L*(i-1)/(n-1);
p = amp*LoadFunctionCP(x,L,type);
Int = Int + wt(i)*p;
end
  댓글 수: 1
Image Analyst
Image Analyst 2018년 5월 20일
편집: Image Analyst 2018년 5월 20일
I fixed your formatting for you. For next time read this link.
What do you consider to be the output of that script? A variable? A file? It's not clear what you think the output should be.
What do you mean by "return"? Do you really want a function instead of a script and want some main program to call that function and have the function return the output in some variable? Or do you simply want your script to keep the variable in the base workspace (like it is now)? Or do you want some file, like a .mat or .xlsx file?
Maybe you want to tell the user what Int is? Like this
message = sprintf('Int = %f', Int)
uiwait(helpdlg(message));

답변 (1개)

JAYANTH BHIMAVARAPU
JAYANTH BHIMAVARAPU 2018년 5월 21일
편집: JAYANTH BHIMAVARAPU 2018년 5월 21일
Generally this message appears when we try to run an empty script or a complete script which is not printing anything In your case the second one was little valid.
The for loop syntax was for i=1:n and not for i = 1;n
So your loop will execute only once and will call LoadFunctionCP(0,3,1) once not 5 times as expected. So please modify your code with these changes.
So based on your function definition you can now check whether you want to print anything or not. You can always do this by just removing the semicolon at the end of that particular statement.
If everything was fine you can just check the content of Int variable manually by double clicking on it in workspace. Hope this helps you.

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

Community Treasure Hunt

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

Start Hunting!

Translated by