Change values in an array based on existing values?
조회 수: 4 (최근 30일)
이전 댓글 표시
I've been looking through previous questions and nothing I've found worked quite well. I thought of using uniquetol but that a) didn't 100% address this problem and b) was not available in 2013a.
I have an array (timestamp_comp) with 2 columns of data. I want to filter the rows in that array based on the value of a cell in another array. Starting out:
%%Finds row in timestamp_comp that approximately matches values in timestamp_meta
e= 1e-5;
crtimestamp_comp=zeros(size(timestamp_comp));
for compare= timestamp_comp(:,2)-timestamp_meta(:,2)
if compare > e
crtimestamp_comp(:,:)=0;
else
crtimestamp_comp(:,:)=timestamp_comp(:,:);
end
end
Here I'm trying to convert all the rows in timestamp_comp that differ more than 1e-5 in the second column from timestamp_meta to zero and then all of the ones that are similar enough are kept.
댓글 수: 0
답변 (1개)
Andrei Bobrov
2016년 2월 21일
Maybe so
crtimestamp_comp = timestamp_comp;
t = abs(timestamp_comp(:,2)-timestamp_meta(:,2)) > 1e-5;
crtimestamp_comp(t,:) = 0;
댓글 수: 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!