How to search and find array in array?
3 views (last 30 days)
Show older comments
Hilal SAKAR
on 12 Sep 2024
Commented: Star Strider
on 13 Sep 2024
Hello,
I create an array below;
bigArray = rand(1,150);
bigArray(1,15:19) = [1 1 1 1 1]';
bigArray(1,25:29) = [1 1 1 1 1]';
bigArray(1,75:79) = [1 1 1 1 1]';
bigArray(1,105:109) = [1 1 1 1 1]';
bigArray(1,65) = 1;
bigArray(1,5:6) = [1 1]';
I want to find [1 1 1 1 1]' array indexes. But I run the code;
idx = find(ismember(bigArray,[1 1 1 1 1]'))
I want to see as an output; [15 16 17 18 19 25 26 27 28 29 75 76 77 78 79 105 106 107 108 109]
0 Comments
Accepted Answer
Star Strider
on 12 Sep 2024
The ismember function is doing exactly what it should. You need to examine ‘bigArray’ tto understand its output.
Try this —
bigArray = rand(1,150);
bigArray(1,15:19) = [1 1 1 1 1]';
bigArray(1,25:29) = [1 1 1 1 1]';
bigArray(1,75:79) = [1 1 1 1 1]';
bigArray(1,105:109) = [1 1 1 1 1]';
bigArray(1,65) = 1;
bigArray(1,5:6) = [1 1]';
disp(bigArray)
Lv = ismember(bigArray,[1 1 1 1 1]')
idx = find(Lv)
.
4 Comments
More Answers (0)
See Also
Categories
Find more on Dictionaries in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!