如何在 Matlab 中的元胞数组中查找大于 0 的所有值

How to find all values greater than 0 in a cell array in Matlab

我想找到所有大于 0 的值并将其保存在一个数组中,并将它们保存在一个名为 "times" 的变量中。我怎么做?保存这些单元格的索引与单元格的实际值有什么区别?

这是我试过的方法,但肯定是错误的,因为我收到错误:

Undefined operator '>' for input arguments of type 'cell'.

clear all, close all

[num,txt,raw] = xlsread('test.xlsx');

times = find(raw(:,5)>0)

要访问单元格的 内容,您必须使用 {} 而不是 ():

idx = find([raw{:, 5}] > 0);

但这会为您提供包含正值的 raw 单元格的 索引 。如果您想要 values,您可以访问它们并将它们收集在数字数组中,方法如下:

times = [raw{idx, 5}];