Function for Script. I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?
0 Kommentare
Akzeptierte Antwort
dpb
am 21 Jan. 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 Kommentare
dpb
am 22 Jan. 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).
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!