Have one array follow another array with a threshhold

Hi there! I've got two arrays and I want to put a threshhold on one of them and have the other array follow it (see example down below). After the threshhold is done, I'd like my array A1 follow the new A2, meaning that the first 3 values of A1 should be removed.
Any tips on how to do this?
A1 = [1 4 5 8 2 2 4];
A2 = [2 5 8 15 18 24 23]
A2Thresh = A2 < 10 | A2 > 30;
A2(A2Thresh) = [ ]

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 3월 24일
편집: Dyuman Joshi 2023년 3월 24일
Use the same approach for A1 as well.
A1 = [1 4 5 8 2 2 4];
A2 = [2 5 8 15 18 24 23];
A2Thresh = A2 < 10 | A2 > 30;
A2(A2Thresh) = []
A2 = 1×4
15 18 24 23
A1(A2Thresh) = []
A1 = 1×4
8 2 2 4
Edit - This works only if both A1 and A2 have same size

댓글 수: 5

Thanks for the reply. That's a really easy and smart solution! Unfortunately, I'm getting the error "Matrix index is out of range for deletion". Any tips?
Please show your whole code.
% I can't seem to post it all, maybe there's to much. Here's the main
% function, whereas VAll and FLWAll are both 1404x1 doubles in matlab
VTHRESH = VAll < 18.69;
VAll(VTHRESH) = [];
FLWTHRESH = FLWAll < 0.10 | FLWAll > 0.30;
FLWAll(FLWTHRESH) = [];
FLWAll(VTHRESH) = [];
When you perform this operation
FLWAll(FLWTHRESH) = [];
The number of elements of FLWALL are reduced, and you can not delete the indices who are greater are the number of elements of FLWALL, which the logical vector VTHRESH might contain.
Thus the error "Matrix index is out of range for deletion".
To resolve the issue, combine the both the conditions together and perform the deletion -
VTHRESH = VAll < 18.69;
VAll(VTHRESH) = [];
FLWTHRESH = FLWAll < 0.10 | FLWAll > 0.30;
FLWAll(FLWTHRESH | VTHRESH) = [];
That did the trick! Thank you for all of your help, really appreciate it! I'll look into it more this weekend so I can avoid these issues in the future

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

2023년 3월 24일

댓글:

2023년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by