找到矩阵

时间:2017-02-04 11:48:05

标签: matlab

我有一个35000 * 200的矩阵,想要确定matlab中每列的第一个非负元素的索引。具体来说,在输出中我想要一个1 * 200向量,其中每个元素是相应列中第一个非负元素的行索引。

感谢。 萨贾德

1 个答案:

答案 0 :(得分:3)

您可以在逻辑上使用max。如果您的数据位于矩阵A中,并且您希望结果位于向量i

[M, i] = max(A >= 0, [], 1); % we find the first non-negative value per column.
i(~M) = 0; % if all values are negative in that column, we output 0 for it.