Coping cell array but skipping a specific column

2 次查看(过去 30 天)
I have:
EMG =
1×3 cell array
{3×16 cell} {3×15 cell} {3×15 cell}
I need to copy the "first" 10 columns of each cell but for each iteration I need to skip column 1, for the second iteration column 2, for the third iteration column 3, and so on. The resulting cell array (3x30) needs to be:
Skipping first column
column1, column2, column3, column4, column5, column6 column28, column29, column30
column2ofcell1, column2ofcell2, column2ofcell3, column3ofcell1,column3ofcell2, column3ofcell3column11ofcell1, column11ofcell2, column11ofcell3
Skipping second column
column1, column2, column3, column4, column5, column6 column28, column29, column30
column1ofcell1, column1ofcell2, column1ofcell3, column3ofcell1, column3ofcell2, column3ofcell3column11ofcell1, column11ofcell2, column11ofcell3
where the column of each cell is copied.
I put the word first in quotations because the columns to be extracted are not contiguous, so it is not always 1:10, the fist iteration is 2:11 because I need to skip #1, on the second iteration I need to skip #2 so I need to copy, 1&3:11, for the third iteration I need to skip #3 and copy 1:2&4:11 and so on until I skip the first 10 columns.
Thank you,

采纳的回答

ErikaZ
ErikaZ 2018-7-5
Not the best code but it works
for cv=1:10
%Create cell array with train data
EMG_InputSeries = []; Angle_TargetSeries = []; Angle_Moment_TargetSeries = [];
EMG_InputSeries=cellfun(@(x) x(:,1:11),EMG,'uni', false);
Angle_TargetSeries=cellfun(@(x) x(:,1:11),Angle,'uni', false);
Angle_Moment_TargetSeries=cellfun(@(x) x(:,1:11),Angle_Moment,'uni', false);
%Delete Test column
for i=1:numel(EMG_InputSeries)
EMG_InputSeries{i}(:,cv)=[];
Angle_TargetSeries{i}(:,cv)=[];
Angle_Moment_TargetSeries{i}(:,cv)=[];
end
%Organize as walk,up,down,walk,up,down
EMG_InputSeries= reshape(vertcat(EMG_InputSeries{:}), [3 30]);
Angle_TargetSeries= reshape(vertcat(Angle_TargetSeries{:}), [1 30]);
Angle_Moment_TargetSeries= reshape(vertcat(Angle_Moment_TargetSeries{:}), [1 30]);
end

更多回答(1 个)

Image Analyst
Image Analyst 2018-7-4
Each of your cells in your cell array contains another cell array. We don't know what that cell array's cells contain but it doesn't matter. To extract/crop out the first 10 columns of the contained cell array, simply do
for k = 1 : length(ca)
thisCellsContents = ca{k}; % This is another cell array
% Take the first 10 columns of the cell array called "thisCellsContents"
ca{k} = thisCellsContents(:, 1:10);
end
Now I have no idea what you mean by iterations. Do you want to put that "crop first 10 columns" code into a for loop where you iterate it for some reason?
  2 个评论
ErikaZ
ErikaZ 2018-7-5
I put the word first in quotations because the columns to be extracted are not contiguous, so it is not always 1:10, the fist iteration is 2:11 because I need to skip #1, on the second iteration I need to skip #2 so I need to copy, 1&3:11, for the third iteration I need to skip #3 and copy 1:2&4:11 and so on until I skip the first 10 columns.
Image Analyst
Image Analyst 2018-7-5
Why do you need to do this?
And please attach your varaible in a .mat file so we can do something with it.

请先登录,再进行评论。

类别

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