Sample evenly-ish vector of unevenly distributed indices

Say I have a vector of indices
v = [v1 v2 v3 v4 v5] = [1 34 456 1345 4567]
I try to find a way to sample v in an evenly-ish way while keepking these points. Is there a quick way to do that instead of a loop over every range between two points [v_i v_j], I have numerous and long vectors...

4 Commenti

Could you talk more about the sampling process? Is this like you want (say) 5 locations within each segment? How should the endpoints be treated, included in both, left is included but right isn't? Except right is included in the last segment? Details!
Perhaps my question is clearer if I say that: I have a vector v, I want to get a new vector vnew in which I have all points of v but also new points so that diff(vnew) does not vary too much.
How about this:
vnew = min(v):max(v);
Now, as long as v contains only integer values, all elements of v are in vnew. And diff(vnew) is all 1s, so the difference is as constant as it can get.
Does that work?
Thanks for your answer. The thing is that the indices can be very large, so I want to refine v but not down to delta=1.

Accedi per commentare.

 Risposta accettata

Matt J
Matt J il 10 Dic 2021
Modificato: Matt J il 10 Dic 2021
Perhaps as follows,
vnew = union( min(v):delta:max(v) ,v);

6 Commenti

Ouatehaouks
Ouatehaouks il 10 Dic 2021
Modificato: Ouatehaouks il 10 Dic 2021
Thanks- This was also my first try indeed, but with this approach the problem is that diff(vnew) can go down to almost zero if min(v):delta:max(v) generates indices close to those of v. So I think that somehow I need to consider every range between each points of v to get the proper delta and then to generate the points but I need to do that without a loop otherwise it is too long.
Easy enough to remove those points:
vnew=uniquetol(vnew,1e-8,'DataScale',1)
Or perhaps, as follows. This ensures that v is preserved within vnew exactly
vnew=min(v):delta:max(v);
tf=ismembertol(vnew,v,tol,'DataScale',1);
vnew(tf)=[];
vnew=union(vnew,v);
I did not know about ismembertol, this is it ! That way I can indeed make sure I get rid of points that are too close from those of v. Thank you for your help !
Sorry I don't know how to accept the correct answer which is in your last comment.
Matt J
Matt J il 10 Dic 2021
Modificato: Matt J il 10 Dic 2021
No problem. Our whole chain of comments is considered part of the "Answer".

Accedi per commentare.

Più risposte (0)

Categorie

Richiesto:

il 10 Dic 2021

Modificato:

il 10 Dic 2021

Community Treasure Hunt

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

Start Hunting!

Translated by