Output Local Variables from a Function - R2, F-Test, Stats, etc.
1 次查看(过去 30 天)
显示 更早的评论
Hello Community,
I have written a function to try to output some key observations about some base data (X,Y). I calculate the r, r2, f-test etc. from the data including calling in the built-in function 'stats'. Code as:
function [r,r2 h,p,ci,stats] = R2Ftest( X, Y )
c=corrcoef([X Y]);
r=c(1,2);
r2=r^2;
figure;
plot(X,Y,'+r');
rsquared = num2str(r2);
title(['XXXX'])
xlabel('XXXX')
ylabel('XXXX')
h = vartest2(X,Y)
[h,p,ci,stats] = vartest2(X,Y,'Alpha',0.01)
Now, everything outputs nicely in my command window, but really I want to have this information output as variables in my workspace that I can subsequently save.
I know I want to avoid using 'global' (I've read enough about this), and thought I had assigned the output arguments as I wanted - but no joy. So, any thoughts on the fix for this?
Thanks in advance.
10B.
0 个评论
采纳的回答
Stephen23
2015-9-22
编辑:Stephen23
2015-9-22
Instead of calling the function like this:
R2Ftest(X,Y)
simply call the function with those outputs:
[r,r2 h,p,ci,stats] = R2Ftest(X,Y)
and they will appear in that workspace. You have defined those outputs inside the function, but it only when it is called do they appear in the calling workspace.
You might like to review the MATLAB tutorials, which cover basic usage like this:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!