필터 지우기
필터 지우기

extract data from matrix and store into a new matirx

조회 수: 2 (최근 30일)
kingsley
kingsley 2018년 2월 6일
댓글: Star Strider 2018년 2월 6일
I want to extract data of row 6 and the last row from the test matrix. Here is my code:
test=[1 2;13 12; 3 0; 4 0; 5 3; 30 10; 2 10; 30 1;10 4; 50 9; 60 7]
data=zeros(2,2);
for j=1:2
for i=1:6
i=1+5;
data(i,j)=test(i,j)
end
end
data
the correct answer should be
data=[30 10 ; 60 7]
however, it comes up with something wrong.

채택된 답변

Star Strider
Star Strider 2018년 2월 6일
You do not need the loop.
This works:
data = test([6 end],:);
data =
30 10
60 7
  댓글 수: 4
kingsley
kingsley 2018년 2월 6일
thank you so much ! it works
Star Strider
Star Strider 2018년 2월 6일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by