problems with function "find". matlab doesn't match two numbere which are built equal
Show older comments
M cannot be found because Matlab says they are different, but i built them in order to be equal. length(data)=7155
clear all;clc;close all;
data0 = load('data0000.txt');
data1 = load('data0001.txt');
data2 = load('data0002.txt');
Rg=17.5;
fs = 100; % Hz
dt = 1/fs;
data= [data0; data1; data2];
time= 0:dt:(length(data)-1)*dt;
N=find(time==12.01);
M=find(time==46.5);
data=data(N:M,:);
time=time(N:M);
1 Comment
Luna
on 6 Oct 2018
Could you please attach data0001.txt and data0002.txt ?
Accepted Answer
More Answers (1)
It is better to compare floats using a tolerance
tol=0.01;
M = find(abs(time-46.5)<tol);
I was however able to find the first number, N, using your code.
N =
1202
the second number, M, is probably in another textfile because there is no value near 46.5 in the one you attached
1 Comment
dpb
on 6 Oct 2018
ismembertol can be useful for such purposes.
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!