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.
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!