Clear Filters
Clear Filters

How to search and find array in array?

23 views (last 30 days)
Hilal SAKAR
Hilal SAKAR on 12 Sep 2024 at 14:44
Commented: Star Strider on 13 Sep 2024 at 10:59
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]'))
idx = 1×23
5 6 15 16 17 18 19 25 26 27 28 29 65 75 76 77 78 79 105 106 107 108 109
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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]

Accepted Answer

Star Strider
Star Strider on 12 Sep 2024 at 14:58
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)
Columns 1 through 18 0.5068 0.9505 0.0516 0.0882 1.0000 1.0000 0.0318 0.3127 0.8880 0.0266 0.9131 0.8241 0.3292 0.0973 1.0000 1.0000 1.0000 1.0000 Columns 19 through 36 1.0000 0.4800 0.7703 0.2106 0.1942 0.6979 1.0000 1.0000 1.0000 1.0000 1.0000 0.4912 0.4754 0.2845 0.7561 0.9840 0.1853 0.1938 Columns 37 through 54 0.4194 0.0772 0.1116 0.3382 0.2339 0.0543 0.3256 0.9436 0.2975 0.6174 0.2227 0.7096 0.5371 0.9033 0.7377 0.5522 0.5055 0.3581 Columns 55 through 72 0.8638 0.2271 0.3195 0.0197 0.4622 0.0299 0.3055 0.4705 0.3989 0.4399 1.0000 0.6735 0.8151 0.1478 0.8166 0.2860 0.6436 0.8295 Columns 73 through 90 0.4801 0.7913 1.0000 1.0000 1.0000 1.0000 1.0000 0.8977 0.8132 0.6884 0.4697 0.2341 0.1666 0.4997 0.6061 0.5467 0.4436 0.5024 Columns 91 through 108 0.8998 0.2705 0.0215 0.1483 0.4976 0.9649 0.5099 0.9422 0.8145 0.3519 0.6390 0.0093 0.5664 0.9736 1.0000 1.0000 1.0000 1.0000 Columns 109 through 126 1.0000 0.7624 0.4387 0.6305 0.1326 0.6353 0.2669 0.3236 0.1274 0.4486 0.2744 0.5949 0.0264 0.7638 0.9727 0.1876 0.1710 0.6894 Columns 127 through 144 0.3853 0.9315 0.9158 0.8965 0.2594 0.0620 0.3116 0.6300 0.4641 0.4008 0.7085 0.1320 0.1949 0.4087 0.7125 0.2770 0.0934 0.5674 Columns 145 through 150 0.4633 0.3660 0.7867 0.9442 0.3935 0.3620
Lv = ismember(bigArray,[1 1 1 1 1]')
Lv = 1x150 logical array
Columns 1 through 45 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 46 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 135 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 136 through 150 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
idx = find(Lv)
idx = 1×23
5 6 15 16 17 18 19 25 26 27 28 29 65 75 76 77 78 79 105 106 107 108 109
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
.
  4 Comments
Hilal SAKAR
Hilal SAKAR on 13 Sep 2024 at 10:53
Thank you very much!
Star Strider
Star Strider on 13 Sep 2024 at 10:59
As always, my pleasure!

Sign in to comment.

More Answers (0)

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!