Matlab not returning variable as intended

• Apr 18th 2010, 01:03 PM
canyon289
Matlab not returning variable as intended
I know this is a super simple problem that has been discussed before but I cannot find the answer for the life of me.
All I want is for this program to output the variable as Y and have it correctly place it in the workspace as Y.

Code:

```function [y] = stress(Ri,Ro,R,Delta,E) %stress = stress(Ri,Ro,R,Delta,E) y = Delta*E/R*1/((R^2+Ri^2)/(R^2-Ri^2)+(R^2+Ro^2)/(R^2-Ro^2)); end```
What am I doing wrong?
• Apr 18th 2010, 02:05 PM
CaptainBlack
Quote:

Originally Posted by canyon289
I know this is a super simple problem that has been discussed before but I cannot find the answer for the life of me.
All I want is for this program to output the variable as Y and have it correctly place it in the workspace as Y.

Code:

```function [y] = stress(Ri,Ro,R,Delta,E) %stress = stress(Ri,Ro,R,Delta,E)   y = Delta*E/R*1/((R^2+Ri^2)/(R^2-Ri^2)+(R^2+Ro^2)/(R^2-Ro^2)); end```
What am I doing wrong?

Where is this function? It should be a function in a file called stress.m (and on the matlab path) or in the script file (I think). It cannot be a sub-function in another .m file.

CB
• Apr 18th 2010, 02:06 PM
canyon289
It's a function file called stress.m, It's not a sub function of anything
• Apr 18th 2010, 02:15 PM
CaptainBlack
Quote:

Originally Posted by canyon289
It's a function file called stress.m, It's not a sub function of anything

Exactly what are the symptoms of it not doing what you expect.

CB
• Apr 18th 2010, 02:30 PM
canyon289
Referring to the attached screenshot

The output of the function is saved as ANS when I want it saved as Y.
See how I inputted a variable for 1, ran my program and it didn't change the value of Y but rather added another scalar named ANS

Thanks for you help
• Apr 18th 2010, 03:04 PM
CaptainBlack
Quote:

Originally Posted by canyon289
Referring to the attached screenshot

The output of the function is saved as ANS when I want it saved as Y.
See how I inputted a variable for 1, ran my program and it didn't change the value of Y but rather added another scalar named ANS

Thanks for you help

y= stress(Ri,Ro,R,Delta,E)

CB
• Apr 18th 2010, 03:07 PM
canyon289
I don't understand. Do I put that in my function file somewhere? Sorry I'm very new to this.
• Apr 18th 2010, 03:35 PM
CaptainBlack
Quote:

Originally Posted by canyon289
I don't understand. Do I put that in my function file somewhere? Sorry I'm very new to this.

no you put it in the command line or top level script, with the input variable assigned to the values you want, or just use numeric values.