필터 지우기
필터 지우기

Find minimum and create a new matrix

조회 수: 2 (최근 30일)
David du Preez
David du Preez 2017년 4월 12일
답변: Andrei Bobrov 2017년 4월 12일
I have a 242x14 matrix. I want to look at the first 22 lines and find the minimum value in column 10. Then I want to create a new matrix including all the columns before the minimum value and a second new matrix containing the minimum value and all the values after it.
I also want to repeat this for the remaining part of the matrix. So in other words I will have two 121x14 matrices.
  댓글 수: 2
KSSV
KSSV 2017년 4월 12일
You want to find minimum value for every 22 rows and them split the matrix, is it?
David du Preez
David du Preez 2017년 4월 12일
Yes that is what I want to do

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 4월 12일
m = size(test_1,1);
i0 = (0:22:m-1)';
ii = ceil((1:m)'/22);
T = test_1(:,10);
T(T == 0) = inf;
idx_min = accumarray(ii,T,[],@(x)find(min(x) == x)) + i0;
ind = zeros(m,1);
ind([idx_min;i0+1]) = 1;
ind = cumsum(ind);
t = rem(ind,2) ~= 0;
Result{1} = test_1(t,:);
Result{2} = test_1(~t,:);

추가 답변 (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