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

6 ビュー (過去 30 日間)
Tomaszzz
Tomaszzz 2021 年 8 月 16 日
コメント済み: Tomaszzz 2021 年 8 月 16 日
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
Tomaszzz
Tomaszzz 2021 年 8 月 16 日
thanks man, indeed as simple as this

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by