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