How to extract data from a specified row number (omitting first row)

7 次查看(过去 30 天)
Hi all,
I have a cell array from which I want to extract data from the rows between parts highlighted yellow in the image below (just part of the array shown).
I want to first indicate the start and end of these rows, as following:
%% find the kewords for start and end
idx_rtoe_start = find(strcmp(data_raw(:, 2), '"Right Toe"'));
idx_rtoe_end = find(strcmp(data_raw(:, 2), '"HX210.11.31.M7-LF S0021"'));
%% indices between idx_rtoe_start and idx_rtoe_end
idx = arrayfun(@(idxStart, idxEnd) idxStart:idxEnd, idx_rtoe_start, idx_rtoe_end,...
'UniformOutput', false);
However, '"HX210.11.31.M7-LF S0021"' occurs for the first time earlier in the file (before 'righ toe') and the code above (bolded part) gives the the first location it occurs. I want this to start from the second time it occurs. I cannot use another keyword as these also occur earlier in the file.
Please help

采纳的回答

Simon Chan
Simon Chan 2021-8-16
Just get rid of the first data in the index:
idx_rtoe_end = find(strcmp(data_raw(:, 2), '"HX210.11.31.M7-LF S0021"'));
idx_rtoe_end = idx_rtoe_end(2:end);

更多回答(1 个)

Tomaszzz
Tomaszzz 2021-8-16
编辑:Tomaszzz 2021-8-16
This does not work beacuse I did not explain well.
Please see part of data attached and the code.
The problem is that this idx_rtoe_end = find(strcmp(data_raw(:, 2), '"HX210.11.31.M7-LF S0021"')) gives me the first location of ''idx_rtoe_end'' 'as 6 (first time '"HX21...'' occurs) whereas I want it to be from 221 and onwards(second time '"HX21...'' occurs and so on; like in the image above) so that I get the variables of interests from the right place (between parts highlighted yellow in the image).
While the idea from Simon could work, the remaining part of the code gives problems.
Thanks
  2 个评论
Simon Chan
Simon Chan 2021-8-16
Just have a quick look on your data and the length of your extracted data should be the same.
Why don't you just set the end index to be start index + (a number)
idx_rtoe_start = find(strcmp(data_raw(:, 2), '"Right Toe"'));
idx_rtoe_end = idx_rtoe_start + 17; % Just an example

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by