Extracting data from cell array using indexes from another cell array

5 views (last 30 days)
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 Comment
Image Analyst
Image Analyst on 26 Jun 2021
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:

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!