I am having trouble returning values to different .m files.
I have tried to declare the variables globally but that doesn't work.
The only way I have found to work is to use the:
save('') and load('')
I know there must be a way without creating this variable file...
For example say I have a file name test.m with code:
function val = test(x) y=x+5; end
and then I make another file called test2.m with code:
and then when I go to
it says undefined function or variable 'y'.
How can i fix this without using save/load variables.
Okay.. You have done two mistakes with this...
1: In the file test.m, the function shall be
function val = test(x) val=x+5; end
receive the sum in the output variable of the function i.e. 'val'
2: In the file test2.m, the code shall be
y = test(5); w=y+5;
receive the output of the function in 'y' before using it