Function for Script. I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?
0 comentarios
Respuesta aceptada
dpb
el 21 de En. de 2015
function [p,n]=splitsigns(x)
% return positive/negative values from array x in vectors p/n, respectively
p=x(x>0);
n=x(x<0);
This one excludes 0; pick where you want those if do...
7 comentarios
dpb
el 22 de En. de 2015
Read the help files on functions, but in general yes. Other than I'd say that p=x(x>0); and n=x(x<0); are expressions, not variables. There are no strictly local variables in those functions, only the input/output arguments (which are, of course variables just not local).
Más respuestas (1)
John Petersen
el 21 de En. de 2015
a = 0.5 - rand(3,3);
%Positive numbers
a(a>=0)
% negative numbers
a(a>0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!