From: Jan Simon on 9 Mar 2010 07:49 Dear Jeremy! > freaky! i just happened to highlight and run selection, it worked, but if i run the file it doesnt! SOMEONE HELP. also im using 7.8.0 (r2009a) (student) Please use the debugger to go through your program line by line. Then you will see which line causes the output. For this question the debugger has a greater competence than the news group. Kind regards, Jan
From: Vadim Teverovsky on 9 Mar 2010 08:52 Are you calling the function like this: >> Mortgage(yyy) If so, you are not assigning the output of the function, and therefore MATLAB puts the output into the variable "ans". If you don't want an output from your function, you can remove the Left-hand-side from your function declaration, whicbh wll make this a function with no outputs. Conversely, you can put a semicolon on the end of the call to Mortgage and "ans" will not display (although it will still be set.) "Jeremy " <arroyo_000021(a)hotmail.com> wrote in message news:hn5d4c$r5g$1(a)fred.mathworks.com... > function [Payment] = Mortgage( Price ) > %This will calculate a mortgage based on your selected input. > %You will be prompted to enter amounts for mortgage, interest, and term. > %To enter Mortgage amount correctly, enter amount in dollars with no > commas > %ex. 100000 for $100,000 you can enter change if desired > %To enter interest rate correctly enter 5.575 for 5.575% not .0575 > %To enter term correctly type in the number of years you wish to have the > %loan ex. 30 > %Created by Jeremy Goff 3/1/10 > clc > format bank > disp(' ') > disp('Follow these steps to calculate a monthly payment') > disp(' ') > Home_Cost=input('Input Home Cost $'); > disp(' ') > down_payment=input('Input down payment (optional) $'); > disp(' ') > Interest_Rate=input('Input Interest Rate As % ')/100; > disp(' ') > Years=input('Input Number Of Years Desired For Financing '); > disp(' ') > Payment=((Home_Cost-down_payment).*(Interest_Rate./12)./(1-(1+(Interest_Rate./12)).^-(Years.*12))); > disp(' ') > fprintf(1,'The monthly payment is $%-7.2f \n',Payment); > > %UNTITLED Summary of this function goes here > % Detailed explanation goes here > > > end > > > this is a copy of what im running, and im getting ans= but in a > different m file im not, i cant see whats different in the two of them > either im pulling my hair out anyone???
From: Jeremy on 9 Mar 2010 09:17 Nice catch, I found that too, and resolved it! Thanks though it was by pure luck I could have been here lost forever. "Vadim Teverovsky" <vteverov(a)mathworks.com> wrote in message <hn5jrh$c4i$1(a)fred.mathworks.com>... > Are you calling the function like this: > >> Mortgage(yyy) > > If so, you are not assigning the output of the function, and therefore > MATLAB puts the output into the variable "ans". > > If you don't want an output from your function, you can remove the > Left-hand-side from your function declaration, whicbh wll make this a > function with no outputs. > Conversely, you can put a semicolon on the end of the call to Mortgage and > "ans" will not display (although it will still be set.) > > > "Jeremy " <arroyo_000021(a)hotmail.com> wrote in message > news:hn5d4c$r5g$1(a)fred.mathworks.com... > > function [Payment] = Mortgage( Price ) > > %This will calculate a mortgage based on your selected input. > > %You will be prompted to enter amounts for mortgage, interest, and term. > > %To enter Mortgage amount correctly, enter amount in dollars with no > > commas > > %ex. 100000 for $100,000 you can enter change if desired > > %To enter interest rate correctly enter 5.575 for 5.575% not .0575 > > %To enter term correctly type in the number of years you wish to have the > > %loan ex. 30 > > %Created by Jeremy Goff 3/1/10 > > clc > > format bank > > disp(' ') > > disp('Follow these steps to calculate a monthly payment') > > disp(' ') > > Home_Cost=input('Input Home Cost $'); > > disp(' ') > > down_payment=input('Input down payment (optional) $'); > > disp(' ') > > Interest_Rate=input('Input Interest Rate As % ')/100; > > disp(' ') > > Years=input('Input Number Of Years Desired For Financing '); > > disp(' ') > > Payment=((Home_Cost-down_payment).*(Interest_Rate./12)./(1-(1+(Interest_Rate./12)).^-(Years.*12))); > > disp(' ') > > fprintf(1,'The monthly payment is $%-7.2f \n',Payment); > > > > %UNTITLED Summary of this function goes here > > % Detailed explanation goes here > > > > > > end > > > > > > this is a copy of what im running, and im getting ans= but in a > > different m file im not, i cant see whats different in the two of them > > either im pulling my hair out anyone??? >
From: Steven Lord on 9 Mar 2010 09:27
"Jeremy " <arroyo_000021(a)hotmail.com> wrote in message news:hn5d4c$r5g$1(a)fred.mathworks.com... > function [Payment] = Mortgage( Price ) *snip* > this is a copy of what im running, and im getting ans= but in a > different m file im not, i cant see whats different in the two of them > either im pulling my hair out anyone??? Let me guess ... you're calling this function like: Mortgage(price) If so, then MATLAB assigns the contents of the variable Payment inside the Mortgage function into the output variable ans in the workspace from which you called Mortgage. Since you didn't end your call to Mortgage with a semicolon, it then displayed the output variable ans. http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ans.html Change your call to: Mortgage(price); or: payment = Mortgage(price); and it should no longer display. Change it to: payment = Mortgage(price) and it should show the contents of the variable payment once the function has finished executing. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ |