How to find a value in column 2 which corresponds to particular value in column 1?
65 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Qaisar Fahim
el 26 de Mzo. de 2022
Comentada: Muhammad Qaisar Fahim
el 27 de Mzo. de 2022
Let say I have a 2 colomn matrix A=[1 3 7 9 4 5 3 2 4; 2 3 1 3 4 5 9 2 4], Based on the value particular vaue in colomn 1 how can I find corresponding value in B for example when I have a value of 9 in then how can I look for corresponding value in colomn 2?
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Mzo. de 2022
I think it's ambiguously worded but I tried to follow your directions as precisely as I could:
format short g
% Define A with 2 rows and 9 columns
A=[1 3 7 9 4 5 3 2 4; 2 3 1 3 4 5 9 2 4]
% Define B
B = rand(size(A))
% Poster says "Based on the value particular vaue in colomn 1
% how can I find corresponding value in B?
% For example when I have a value of 9 in then how can I look for corresponding value
% in colomn 2?"
% Find a particular value in A's column 1.
% The location of that value was not specified by the poster.
% Let's say that you want the value in the first row of column 1 of A.
value = A(1,1) % = 1 for this example.
% Now assume that value we want that value from the corresponding row (1)
% of matrix B but in column 2. In other words B(1, 2)
output = B(value, 2)
10 comentarios
Image Analyst
el 27 de Mzo. de 2022
Node1 is either true or false, not an index like you'd get from find()
Node1 = find(Slope_Indices(:,1) == Node);
I think you can invest 2 hours in this
and learn how to do it yourself. It's just basic indexing. If you can't do this then you're going to have trouble with every other step beyond this. So learn the basics and you'll be self sufficient.
Más respuestas (1)
KSSV
el 26 de Mzo. de 2022
A=[1 3 7 9 4 5 3 2 4; 2 3 1 3 4 5 9 2 4] ;
idx = A(1,:)==9
iwant = A(2,idx)
Ver también
Categorías
Más información sobre Matrix Indexing 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!