Remove column based on row value

3 次查看(过去 30 天)
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