Reproducing elements from one vector to another.

9 vues (au cours des 30 derniers jours)
Johan Edholm
Johan Edholm le 14 Mai 2019
Modifié(e) : Jan le 15 Mai 2019
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:
Skärmavbild 2019-05-14 kl. 11.37.29.png
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 commentaires
Johan Edholm
Johan Edholm le 14 Mai 2019
Thanks for the tips, will include everything next time. Did manage to solve it with unique, find, isfinite, double, and sum. By first separating the unique values in time_543, and making a new vector, with all the time steps from the first to the last, with 3 hours increments, as well as a empty vector to fill with how many times each time step is repeated, or zero.
aa = unique(time_543);
cc = datenum(2011,12,09,09,00,00):0.125:datenum(2012,03,06,06,00,00);
bb = zeros(1,length(cc));
for i=1:length(time_543)
I(i) = find(cc==aa(i),1);
end
dd(I) = aa;
for i=1:704
bb(i) = sum(double(isfinite(find(time_543==dd(i)))));
end
After this, I just used repelem with the other data set and bb. Hope this is clear enough for anyone having the same problem.
Jan
Jan le 15 Mai 2019
Modifié(e) : Jan le 15 Mai 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);
I'm still not sure what you want to achieve actually.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by