Change values in an array based on existing values?

5 次查看(过去 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.

回答(1 个)

Andrei Bobrov
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;

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by