Extracting data from cell array using indexes from another cell array

조회 수: 8 (최근 30일)
Nickolai Martonick
Nickolai Martonick 2021년 6월 26일
댓글: Image Analyst 2021년 6월 26일
Hello,
I have a 2x10 cell array (kneeX) containing cells with single collumns of data (i.e. 750x1). I want to cut this data using indexes for (ic) and (minCOM). The indexes for (ic) are in a 2x10 cell array and the indexes for (minCOM) are likewise in another 2x10 cell array. I am using a for loop to call in all my data.
Here is my code for calling in kneeX from my data structure.
kneeX{i,j} = data.(names{i}).Lt_Knee_Pos{j}(:,1);
However, when I try to extract my kneeX data from ic to minCOM
kneeX{i,j} = data.(names{i}).Lt_Knee_Pos{j}(:,1)(ic{j}:minCOM{j});
I get the error, "Indexing with parentheses '()' must appear as the last operation of a valid indexing expression."
Is there a way to do this with cell arrays. Previously I have been able to cut my data using a code like this when not using a cell array for my indexing.
for i = 1:10;
Landing{i} = PreVGRF{i}(ic(i):minCOM(i));
end
  댓글 수: 1
Image Analyst
Image Analyst 2021년 6월 26일
I think you're trying to do too much in one expression. Sometimes/often it's better to do things explicitly where you can understand things than to make a cryptic and compact one liner. Heck, even a for loop might be more readable than some cryptic one liner with tons of parentheses and braces. Plus it can be tricky knowing when to use a brace, parenthesis, or bracket. It would help us to help you if you had remembered to upload your kneeX and data variables in a .mat file. Here's another change to read the posting guidelines:

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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