Reproducing elements from one vector to another.
1 view (last 30 days)
Show older comments
Hi!
I have a problem that I can't wrap my head around. Two data sets, one with a matrix with values (depth x time), and a time vector, and the other with a vector of values, along with a time vector. The time step is three hours. The first set however, is irregular, with some time steps being repeated (due to a higher temporal resolution), looks like this:

Now, how should one do to get the elements from the second data set replicated in the same way as the first? I.e. like using repelem but with irregular increments. Appreciate any help, thanks!
Johan
3 Comments
Jan
on 15 May 2019
Edited: Jan
on 15 May 2019
This is not really meaningful:
bb(i) = sum(double(isfinite(find(time_543==dd(i)))));
find() replies the indices of non-zero elements of its input. Indices are finite in every case, so the isfinite() is not useful here. sum() operates on logcial arrays directly, so the casting to double() is not required. You can get the same result by:
bb(i) = sum(time_543 == dd(i));
The approach
cc = datenum(2011,12,09,09,00,00):0.125:datenum(2012,03,06,06,00,00);
is fragil due to rounding errors, see https://www.mathworks.com/matlabcentral/answers/57444-faq-why-is-0-3-0-2-0-1-not-equal-to-zero
I'm still not sure what you want to achieve actually.
Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!