Function for Script. I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?
6 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
dpb
2015 年 1 月 21 日
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 件のコメント
dpb
2015 年 1 月 22 日
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).
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!