How can I find same values in (data range) matrices?

1 view (last 30 days)
Hello!
I'd like to write a script to find same values from different matrices but the first matrix contains different time ranges. for example: I have an 'events' matrix contains time events. Another matrix (start) contains start time of waves, and (end) contains end time of waves.
I have four matrix array in rows:
events
0.165
0.187
0.982
1.258
1.569
2.263
start end time_series
0.002 0.189 0.001
0.196 0.990 0.002
1.145 1.601 0.003
1.698 2.996 0.004
..... ..... .....
So I would create a script, that find the time events in the different time ranges from matrix contains the continues time series data.
My code:
lgt_start = length(start);
lgt_end = length(end);
lgt_events = length(events);
for i = 1:lgt_events;
for l = 1:lgt_start;
for m = 1:lgt_end;
times(i,1) = find (time_series(lgt_start(l,1):lgt_end(m,1)) == events(i,1));
end
end
end
When I run this script the Matlab write the following error: 'Subscripted assignment dimension mismatch'.
Can you help me somebody how to correct the script?
Thank you for the answers,
Janos.

Answers (2)

Star Strider
Star Strider on 13 Dec 2014
I cannot run your code, but one possible solution would be to create ‘times’ as a cell array:
times{i} = find (time_series(lgt_start(l,1):lgt_end(m,1)) == events(i,1));
I also suggest changing your variable name to ‘time_vct’ or something else that is meaningful in the context of your code, because times is the name of a built-in MATLAB function that does element-wise multiplication. This will cause problems if you need to use it in a function, as ‘@times’.
  2 Comments
Janos Horváth
Janos Horváth on 15 Dec 2014
Thank you for your answer. I try to run the code that you offer. Yes indeed the name-time not a best choice as matrix name.... thanks.

Sign in to comment.


Image Analyst
Image Analyst on 15 Dec 2014
Don't test for equality with floating point numbers , test for tolerance. See the FAQ.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!