필터 지우기
필터 지우기

How can I format numeric arrays that are too long

조회 수: 4 (최근 30일)
Hatice Sahin
Hatice Sahin 2019년 5월 23일
댓글: Hatice Sahin 2019년 5월 23일
Hi,
I am using UNIX timestamps in 2 different datasets in Matlab 2019.
eog_time=[1.556122932190000e+12
1.556123223410000e+12
1.556124030209000e+12]; %shortened sample array
flanker_time= 1.556123166337000e+09;
I want to find the closest time in eog_time to the flanker_time. However the format doesn't let me.
target=dsearchn(flanker_time, eog_time)
gives me the first value in my eog_time array.
If I delete the e+09 and e+12 parts from my arrays I will still have the necessary info and I can compare these two arrays. I tried format
format long
and
format longG
but it only works in 1 numeric value, not for the array. Any ideas how can I shorten my numbers so dsearchn would work? Or even a better way to reach the target value?
thank you.
  댓글 수: 3
Jan
Jan 2019년 5월 23일
I guess the different magnitude are the result of useing different function for reading the values, and at least one of these methods is flawed. The clean solution would be to get the correct time stamps directly.
Hatice Sahin
Hatice Sahin 2019년 5월 23일
@jan : The clean solution would be to get the correct time stamps directly.
Unfortunately I am only combining these two data streams, data was provided to me.
@guillaume
It's like saying that 15 (1.5e1) is closer to 15000 (1.5e4) than to 10000(1.0e4).
You have a point. I have turned time stamps into normal date format. they seemed to keep the miliseconds when they are 16 digits.
for example: 1556122932190000 gives me Wednesday, 24 April 2019 16:22:12.190
So I thought I wouldn't have problems if I reduce the number.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2019년 5월 23일
편집: Jan 2019년 5월 23일
The format command affects only the display in the command window. This does not change the data or the method for the comparison in any way.
"the format doesn't let me" is not clear. It is not a question of the "length" or the format, but the vector contains values, which are 1000 times larger than the searched value.
"If I delete the e+09 and e+12 parts from my arrays": This means to divide one array by 1e9 and the other by 1e12.
eog_time=[1.556122932190000e+12
1.556123223410000e+12
1.556124030209000e+12];
flanker_time = 1.556123166337000e+09;
list = eog_time / 1e12;
search = flanker_time / 1e9;
[~, index] = min(abs(list - search))
Or cheaper:
list = eog_time / 1e3;
search = flanker_time;
[~, index] = min(abs(list - search))
By the way, dsearchn is an overkill. min(abs(a-b)) is much cheaper.
  댓글 수: 1
Hatice Sahin
Hatice Sahin 2019년 5월 23일
thank you so much. The code below solved my problem.
list = eog_time / 1e3;
search = flanker_time;
[~, index] = min(abs(list - search))

댓글을 달려면 로그인하십시오.

추가 답변 (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