Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Image Analyst
Image Analyst le 20 Mai 2018
Modifié(e) : Image Analyst le 20 Mai 2018
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));

Réponses (1)

JAYANTH BHIMAVARAPU
JAYANTH BHIMAVARAPU le 21 Mai 2018
Modifié(e) : JAYANTH BHIMAVARAPU le 21 Mai 2018
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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by