How should i write a code to pull up a specific data from column?

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)

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

I want matlab to display index 3, 4 and 5. that is till the point when it went back up to normal. And if there are for example 100 such instances then displaying x=100 i.e number of times such instance took place. This is how i was thinking to code.
for
i=(1:6503); j=7;
if A(i-1,j)+10<A(i,j)<A((i+1),j)+10
I want matlab to shown how many times this occurs like 57 times or something. And also i want matlab to diplay those values for reference. I know its not correct but thats how i was thinking.
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.
A=x_123 % it's a excel worksheet which has 6505 rows, and 10 columns
for i=(2:1:6503)
for j=7;
% 41 is my initial value as per your initial comment.
if A(i,j)<41;
T=(A(i,j));
disp(T);
end
end
end
how do i count the total occurrences of T which are less than 41?
nnz(A(2:end-2,7) < A(1,7))
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) );

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 3 de Jul. de 2016

Comentada:

el 4 de Jul. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by