I have an 300x2 array in which I need to find a certain numbert in colum 1, e.g. 10. Once the number is found I need to extract the corresponding value in colum 2.

 채택된 답변

Chunru
Chunru 2021년 6월 8일

1 개 추천

idx = A(:, 1) == 10; % find the index that 1st column = 10
b = A(idx, 2); % extract the corresponding data in 2nd column
Or in one line
b = A(A(:,1)==10, 2);

댓글 수: 1

Thanks :) ! it is really that simple. I literally just started with MATLAB

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 6월 7일

댓글:

2021년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by