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

5 views (last 30 days)
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

Accepted Answer

Simon Chan
Simon Chan on 16 Aug 2021
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);

More Answers (1)

Tomaszzz
Tomaszzz on 16 Aug 2021
Edited: Tomaszzz on 16 Aug 2021
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 Comments
Simon Chan
Simon Chan on 16 Aug 2021
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!