How do I get the row numbers of the 'list' where the values are equal to the values of the array 'days'

조회 수: 1 (최근 30일)
%clear;
%close all;
%clc;
list = [
50 74;
6 34;
147 162;
120 127;
98 127;
120 136;
53 68;
145 166;
95 106;
242 243;
222 250;
204 207;
69 79;
183 187;
198 201;
184 199;
223 245;
264 291;
100 121;
61 61;
232 247;
153 181;
197 216;
283 307;
194 199;
82 109;
10 25;
60 90;
256 271;
172 173;
];
M = sortrows(list);
out = M(sum(squeeze(any(M - permute(M,[3,2,1]) <= 0,2))) == 1:size(list,1),:);
[days] = out(:,1);

채택된 답변

Robert U
Robert U 2019년 10월 17일
Hi Yannick Leroy,
the function ismember() allows to compare matrices with vector elements. The function find() supplies the indices. You don't need to use find() if you can utilize logical indexing.
[ind,~] = find(ismember(list,days)) % find row index only
ind = unique(ind); % remove duplicates
Kind regards,
Robert

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by