How to insert data to a matrix based on index values stored in a matrix?
Afficher commentaires plus anciens
Hello!
I am a beginner in Matlab and would like to ask a question regarding inserting NaN- values to a matrix according to index values that are stored in a matrix.
I have the following case:
a is a matrix containing data I want to insert NaN- values to the start and end of the vector.
a = vector 250x111
b is a matrix where first row has index values of the start cut-off point and second row information of end cut-off point. For example start cut-off point could be 20 and end cut-off point 105 for a certain data point.
b = matrix 2x111
I believe I can implement this with following by using for- loop through data (example for the first data point):
a( 1:b(1,1) ) = NaN;
a( b(2,1):end) = NaN;
However, I am wondering if there is a way or function to conduct this smoothly? I have noticed while reading this forum that there is usually more efficient ways than using for- loops to conduct this kind of operations and there for wanted to ask for tips.
Thank you already in advance!
2 commentaires
Stephen23
le 16 Juin 2021
As you have just one vector, surely this is just:
a(1:max(b(1,:))) = NaN;
a(min(b(2,:)):end) = NaN;
(note that in your example you have swapped the row and column indexing).
Martti Ilvesmäki
le 16 Juin 2021
Modifié(e) : Martti Ilvesmäki
le 17 Juin 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!