Change values in an array based on existing values?
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Andrei Bobrov
on 21 Feb 2016
Maybe so
crtimestamp_comp = timestamp_comp;
t = abs(timestamp_comp(:,2)-timestamp_meta(:,2)) > 1e-5;
crtimestamp_comp(t,:) = 0;
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!