Reproducing elements from one vector to another.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2019-5-15
编辑:Jan
2019-5-15
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!