Hi,
I am still new using MATLAB. For your information, I have the data at the workspace (40000 x 7 double) but how can I extract the data at the row with the value of the first column is 1 or 2? Thank you in advance.

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2023년 1월 3일
편집: Bjorn Gustavsson 2023년 1월 3일

0 개 추천

You can do things like this in matlab:
data_oi = data(data(:,1)==1|data(:,1)==2,:);
This wouild give you your data of interest in a variable data_oi where the elements in the first column is either a 1 or a 2. If you're this new to matlab, then one good recommendation is to browse through the on-ramp material - which is a introductory information presentation.
HTH

댓글 수: 2

Fouziah Yassin
Fouziah Yassin 2023년 1월 4일
Many thanks for the answer and it's really helpful. Really appreciate it. I tried it and understood how it worked.
My pleasure, happy that it helped.

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

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2023년 1월 3일

0 개 추천

If your data is A , the rows that contains 1 in the first column are defined by ind1
see example below
% dummy data
A = rand(10,10);
A(:,1) = randi(3,10,1);
% extract data when first column contain 1
ind1 = (A(:,1)==1); % logical index
A1 = A(ind1,:) % A extract for first column containing 1's
% extract data when first column contain 2
ind2 = (A(:,1)==2); % logical index
A2 = A(ind2,:) % A extract for first column containing 2's

댓글 수: 1

Fouziah Yassin
Fouziah Yassin 2023년 1월 4일
Thank you for the code with the explanation. It is really useful for me to learn.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by