Removing values from two different variables
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have attached two variables, AL.mat and QRS.mat. AL.mat is a 1x48 cell containing labels 0, 1 and 2. QRS.mat is also a 1x48 cell and it contains peak indices.
Basically, I want to remove all the 2's from the AL variable. Simultaneously, I want to remove the peak indices that correspond to these 2's in the QRS variable. How can I do that?
댓글 수: 0
채택된 답변
the cyclist
2020년 2월 10일
% For each cell of AL, find the non-2's
keepIndices = cellfun(@(x)x~=2,AL,'UniformOutput',false);
% Keep the elements of AL that are non-2's
AL_no_2 = cellfun(@(x,y)x(y),AL, keepIndices,'UniformOutput',false);
% Keep the elements of QRS that are non-2's
QRS_no_2 = cellfun(@(x,y)x(y),QRS,keepIndices,'UniformOutput',false);
댓글 수: 7
the cyclist
2020년 2월 13일
Sure, it is possible to implement. But it won't be a few simple lines of code like your original question. And I don't think you can do the entire cell array at once. The steps will be something like
- Define a for loop that processes each element of the cell array in turn
- For each element of the cell array AL, find the indices of the 2's. (You could use the find command.)
- Use those to determine the indices just before and after that stretch of 2's
- Do the math on QRS that you describe above
In a manner of speaking, it is much more of an algorithm, than a couple slick MATLAB command.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
