String 在大型MATLAB表格中查找字符串(关键字)
我有大型MATLAB表格(2.000.000 x 30),第一列有时间戳,第二列有参数组关键字。第三列有参数名,下一列有参数值。然后是更多的参数和值对 示例数据:String 在大型MATLAB表格中查找字符串(关键字),string,performance,matlab,String,Performance,Matlab,我有大型MATLAB表格(2.000.000 x 30),第一列有时间戳,第二列有参数组关键字。第三列有参数名,下一列有参数值。然后是更多的参数和值对 示例数据: 2012-08-28 13:37:46:573, m_IVS_AU_SystemManager_FlashLast, flashLast, 9, ... 2012-08-28 13:37:46:573,m_IVS_AU_SystemManager_CPULast,cPULast,51, ... 2012-08-28 1
2012-08-28 13:37:46:573, m_IVS_AU_SystemManager_FlashLast, flashLast, 9, ...
2012-08-28 13:37:46:573,m_IVS_AU_SystemManager_CPULast,cPULast,51, ...
2012-08-28 13:37:46:573,m_IVS_AU_SystemManager_NetworkLast,networkLast,0, ...
2012-08-28 13:37:48:558,m_F121_KantenKB,kantenKB,0, KantenKU, 1, ...
2012-08-28 13:37:48:589,m_F121_HmiVollstaendig,hmiVollstaendig,TRUE:0, ...
2012-08-28 13:37:49:042,m_F22_IVS_IsecTrkServiceState,isecTrkServiceState,3, ...
2012-08-28 13:37:49:120,m_F121_HmiUpdate,hmiUpdate_PresentationsId,0, ...
我的任务
我需要从这个MATLAB表中提取与关键字列表匹配的条目(例如:m_IVS_AU_SystemManager_FlashLast
),并将时间戳和参数值保存到一个新的MATLAB表中
有没有一种(快速)的方法来做类似的事情
rows = MyTable.parameterKeyword == 'm_IVS_AU_SystemManager_FlashLast'
就像MATLAB中的数字一样,如果在该行中找到关键字,则返回包含逻辑true(1)的逻辑数组,否则返回零
链接
逻辑数组
例如:
% Dummy table
B = table(['M';'F';'F';'F'],[47;31;35;23],[68;64;62;58],...
'VariableNames',{'Gender' 'Age' 'Height'},...
'RowNames',{'Joe' 'Meg' 'Beth' 'Amy'});
mask = ismember(B.Gender, 'F');
whos mask
返回:
mask =
0
1
1
1
Name Size Bytes Class Attributes
mask 4x1 4 logical
如下文所述,如果查询仅针对一个字符串,则可用于边际速度提升
我在下面附上了一些简单的时间安排:
function testcode(nentries)
A = table(repmat({'hi'}, nentries, 1), 'VariableNames', {'Thing1'});
t1 = timeit(@()ismember(A.Thing1, 'hi'));
t2 = timeit(@()strcmp(A.Thing1, 'hi'));
t3 = timeit(@()strcmpi(A.Thing1, 'hi'));
tmp = ver;
fprintf(['Timing for %d entries %s:\n' ...
' ismember: %.5f\n' ...
' strcmp: %.5f\n' ...
' strcmpi: %.5f\n\n'], nentries, tmp.Release, t1, t2, t3);
end
对于testcode(5e6)
我的机器上的计时如下:
Timing for 5000000 entries (R2016a):
ismember: 0.09246
strcmp: 0.06575
strcmpi: 0.07284
您可以使用,它将返回一个逻辑
数组
例如:
% Dummy table
B = table(['M';'F';'F';'F'],[47;31;35;23],[68;64;62;58],...
'VariableNames',{'Gender' 'Age' 'Height'},...
'RowNames',{'Joe' 'Meg' 'Beth' 'Amy'});
mask = ismember(B.Gender, 'F');
whos mask
返回:
mask =
0
1
1
1
Name Size Bytes Class Attributes
mask 4x1 4 logical
如下文所述,如果查询仅针对一个字符串,则可用于边际速度提升
我在下面附上了一些简单的时间安排:
function testcode(nentries)
A = table(repmat({'hi'}, nentries, 1), 'VariableNames', {'Thing1'});
t1 = timeit(@()ismember(A.Thing1, 'hi'));
t2 = timeit(@()strcmp(A.Thing1, 'hi'));
t3 = timeit(@()strcmpi(A.Thing1, 'hi'));
tmp = ver;
fprintf(['Timing for %d entries %s:\n' ...
' ismember: %.5f\n' ...
' strcmp: %.5f\n' ...
' strcmpi: %.5f\n\n'], nentries, tmp.Release, t1, t2, t3);
end
对于testcode(5e6)
我的机器上的计时如下:
Timing for 5000000 entries (R2016a):
ismember: 0.09246
strcmp: 0.06575
strcmpi: 0.07284
您是在搜索表中的特定变量(列)还是整个内容?我总是在第二列中搜索某些关键字。您是在搜索特定变量(列)在您的表中还是在整个内容中?我总是在第二列中搜索某些关键字。strcmp
也可以用于只查找一个字符串的情况,好处是您可以执行strcmpi
来进行不区分大小写的匹配。@SomeGuy true,我添加了比较strcmp
,如果您只查找一个字符串,也可以使用它,好处是您可以使用strcmpi
进行不区分大小写的匹配。@SomeGuy true,我添加了比较