Matlab 获取字符串不为空的行号
我有一个单元格数组,它有4列和大约2000行。在第二列中有一些字符串值。我需要在有文本的地方得到这些值的行号。我所能做的似乎就是得到一个返回的逻辑向量,它并不是我真正想要的Matlab 获取字符串不为空的行号,matlab,Matlab,我有一个单元格数组,它有4列和大约2000行。在第二列中有一些字符串值。我需要在有文本的地方得到这些值的行号。我所能做的似乎就是得到一个返回的逻辑向量,它并不是我真正想要的 ID New ID 123 956 987 655 321 656 987 144 329 所以我想要一个返回行号[3,4,6]的向量。只需通过find将逻辑索引转换为数字索引即可 index = find(~cellfun(@isempty, array(:, 2))) 只需通
ID New ID
123
956
987 655
321 656
987
144 329
所以我想要一个返回行号[3,4,6]的向量。只需通过
find
将逻辑索引转换为数字索引即可
index = find(~cellfun(@isempty, array(:, 2)))
只需通过
find
将逻辑索引转换为数字索引即可
index = find(~cellfun(@isempty, array(:, 2)))
如果要查找第二列中包含某些文本(字符串)的行,可以使用并对照所有第二列条目进行检查 代码
%%// Create some random cell array for demo
cell_array1 = cell(4,2);
cell_array1(:,1) = {34,45,22,12};
cell_array1(:,2) = {'hmm',45,'say',12}
%%// Required row indices
ind = find(cellfun(@ischar, cell_array1(:, 2)))
输出
cell_array1 =
[34] 'hmm'
[45] [ 45]
[22] 'say'
[12] [ 12]
ind =
1
3
如果要查找第二列中包含某些文本(字符串)的行,可以使用并对照所有第二列条目进行检查 代码
%%// Create some random cell array for demo
cell_array1 = cell(4,2);
cell_array1(:,1) = {34,45,22,12};
cell_array1(:,2) = {'hmm',45,'say',12}
%%// Required row indices
ind = find(cellfun(@ischar, cell_array1(:, 2)))
输出
cell_array1 =
[34] 'hmm'
[45] [ 45]
[22] 'say'
[12] [ 12]
ind =
1
3