How should i write a code to pull up a specific data from column?
Mostrar comentarios más antiguos
suppose I have a column vector with random values and I want to pull up values those are at a difference of 10, into a variable. lets say, A=(40;42;45;20;45;40;44;43;30;45), i.e 10 values and i want to write a code to register all the values where there's a difference of min 10 in the values in a particular order. ex: 45,20,45 has a min 10 difference so register that value in a variable 'x'. this thing happens twice in this column vector. please let me know if any one knows the coding needed for that. I am new to MATLAB and coding so help is needed.
Respuestas (1)
Walter Roberson
el 3 de Jul. de 2016
find(abs(diff(A)) >= 10)
However, you have not been clear as to whether you want to find the first or the second of the two numbers. In your example, 45 is at index 3 and the 20 that is more than 10 different is at index 4, so would you want to it to indicate 3, or would you want it to indicate 4, or would you want it to indicate both 3 and 4?
5 comentarios
Neeraj Dubbalwar
el 3 de Jul. de 2016
Editada: Neeraj Dubbalwar
el 3 de Jul. de 2016
Walter Roberson
el 3 de Jul. de 2016
Talking about it going back up to "normal" is not compatible with your previous description. For example, if the values had been A=[40; 42; 45; 20; 25; 45 ;40; 44; 43; 30; 45] then the 20 and 25 would be within 10 of each other so by your earlier description that should be the end of the partial run. Consider too A=[40;42; 45; 20; 27; 36; 45; 40; 44; 43] then after the fall between 45 and 20, all of the remaining values are within 10 of the adjacent value, so none of them should trigger some kind of "end of run" condition.
When you talk about "normal" you start to need to talk not about difference between adjacent values and instead talk about absolute values, such as determining that 27 is not "normal" because it is below (40-10) but that the 36 is "normal" because it is above (40-10) where the 40 is the initial value.
Neeraj Dubbalwar
el 4 de Jul. de 2016
Editada: Walter Roberson
el 4 de Jul. de 2016
Walter Roberson
el 4 de Jul. de 2016
nnz(A(2:end-2,7) < A(1,7))
Walter Roberson
el 4 de Jul. de 2016
Or in more vectorized form for multiple columns:
targetcols = [3, 7]; %multiple columns
num_lower_than = sum( A(2:end-2, targetcols) < repmat(A(1, targetcols), size(A,1)-3, 1) );
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!