how to find the equivalent value in the same row of the next column?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to know the value in the same row in the next column of the last repeating value in column 1, for example in column 1 the value 28 stops in row 3, then its corresponding value in column 2 is 13.
28 1
28 2
28 13
30 11
30 22
30 30
0 comentarios
Respuestas (2)
Prasanth Sikakollu
el 10 de Jun. de 2019
Use a for loop to iterate over the values in 1st column and if the required condition is satisfied, append the value in the 2nd column of respective row to the answer.
The following code does that.
data = [28 1; 28 2; 28,13; 30 11; 30 22; 30 30];
cur_val = data(1,1);
ans = [];
for i = 1:length(data)
if cur_val ~= data(i,1) % checking if it is the last repeating value in column 1
ans = [ans data(i-1,2)]; % appending the value in the 2nd column of the previous row to the ans
cur_val = data(i,1);
end
end
ans = [ans data(end,1)];
Hope it helps in solving your problem.
0 comentarios
Raj
el 10 de Jun. de 2019
Use this:
data = [28 1; 28 2; 28,13; 30 11; 30 22; 30 30];
A=diff(data(:,1));
data(:,1)=[A;0];
temp=find(data(:,1)~=0);
temp1=data(end);
Required_Answer=[data(temp,2) ;temp1]
0 comentarios
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!