Remove column based on row value

조회 수: 1 (최근 30일)
Jonathan Lam
Jonathan Lam 2024년 7월 3일
댓글: Taylor 2024년 7월 3일
Hello all,
A bit new to MATLAB but I have a matrix M that is [2x19]. In the first row are x-values derived from another function, but I want to return a new matrix that excludes the columns in M with an x-value larger than 4 in this case
100 0.909090909090909 1 1.01010101010101 1.13636363636364 1.29870129870130 1.50000000000000 1.51515151515152 1.81818181818182 2 2.27272727272727 2.50000000000000 3 3.03030303030303 3.50000000000000 4 4.50000000000000 4.54545454545455 5
18 1 0.909090909090909 0.900000000000000 0.800000000000000 0.700000000000000 0.606060606060606 0.600000000000000 0.500000000000000 0.454545454545455 0.400000000000000 0.363636363636364 0.303030303030303 0.300000000000000 0.259740259740260 0.227272727272727 0.202020202020202 0.200000000000000 0.181818181818182
I know it might seem like a simple question but I can't seem to use the M = M(M(1,:)<=4, M(:,1) nonmenclature correctly. Would appreciate any help

채택된 답변

Taylor
Taylor 2024년 7월 3일
A = [1 2 5; 3 4 6; 2 8 9]
A = 3x3
1 2 5 3 4 6 2 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
colsToKeep = ~any(A > 4, 1)
colsToKeep = 1x3 logical array
1 0 0
B = A(:, colsToKeep)
B = 3x1
1 3 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 2
Jonathan Lam
Jonathan Lam 2024년 7월 3일
Thanks so much, I was able to get it with your help.
Taylor
Taylor 2024년 7월 3일
Great! You were on the right track with the logical indexing. any and all are quite useful functions when performing logical indexing.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by