Borrar filtros
Borrar filtros

Output Local Variables from a Function - R2, F-Test, Stats, etc.

2 visualizaciones (últimos 30 días)
10B
10B el 22 de Sept. de 2015
Comentada: 10B el 22 de Sept. de 2015
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.

Respuesta aceptada

Stephen23
Stephen23 el 22 de Sept. de 2015
Editada: Stephen23 el 22 de Sept. de 2015
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:
  1 comentario
10B
10B el 22 de Sept. de 2015
Ah - Thanks Stephen. Another schoolboy error on my behalf, all the more amusing as I had actually written the answer myself at the start of the function! I will now know for next time.
10B

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by