필터 지우기
필터 지우기

How can I extract exact values from a single column of a matrix?

조회 수: 11 (최근 30일)
Sam Hurrell
Sam Hurrell 2021년 7월 5일
답변: Star Strider 2021년 7월 5일
The matrix in question has x, y, z coordinates in its first 3 columns respectively. I tried using a for-loop to go through the matrix and if it came across a row where x=0.025 then it would copy the entire row to a second matrix in it's 'f' row then f=f+1. The second matrix was premade with zeros and is the correct size, however it keeps resulting in no change to it.

채택된 답변

Star Strider
Star Strider 2021년 7월 5일
Try something like this —
M = randi(50, 50, 3)/1000 % Original Matrix
M = 50×3
0.0220 0.0010 0.0070 0.0320 0.0060 0.0030 0.0280 0.0440 0.0110 0.0140 0.0280 0.0050 0.0360 0.0220 0.0170 0.0110 0.0390 0.0350 0.0020 0.0410 0.0480 0.0030 0.0060 0.0260 0.0250 0.0060 0.0320 0.0050 0.0290 0.0380
Lv = M(:,1) == 0.025 % Logical Vector 'Mask'
Lv = 50×1 logical array
0 0 0 0 0 0 0 0 1 0
nrtrue = nnz(Lv) % Number Of Occurrences (Optional)
nrtrue = 3
N = M(Lv,:) % New Matrix
N = 3×3
0.0250 0.0060 0.0320 0.0250 0.0480 0.0420 0.0250 0.0010 0.0100
Make appropriate changes to get the result you want.
.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by