Need to access only few samples from and an array
Show older comments
Hi I have a matrix and instead of traversing sequentially I need to traverse randomly. So I use another array to random the index of the matrix and use if for traversing. Now From that pseudorandom i do not want one row of the matrix to be processed and I am not getting desired result. Can you help me with it. Below is the code and explanation of the same.
a=[10 12 16 15; 3 4 8 0; 14 11 4 1; 7 6 15 9;]
b=a';
d=b(:)';
[r,c]=size(a);
seed_key = 123456; % key
rng(seed_key); % seed the random number generator
idxs1 = randperm(r*c);
cnt_rnj=1;
half=r*c/2;
halfend=half+r;
inx=find(idxs1>half & idxs1<halfend+1);
for i=1:length(d)
if (i~=idxs1(inx(cnt_rnj)))
% idd(i)=1; //to check how the loop is processing
else
%idd(i)=2; // to check how the loop is processing
cnt_rnj=cnt_rnj+1
YN=i
end
end
Basically if it is a 4x4 matrix I do not wanted index position 9,10,11,12 to be processed. If I had to do it sequentially it is not an issue but as I am traversing the randomly the index position will not be in order in the idxs1 matrix. Here for example matrix inx has the position of [9,10,11,12] of array d as [1,7,9,11]. Using the if (i~=idxs1(inx(cnt_rnj))) it evaluates position 9,11,12 but misses 10th index. Can you please help me to solve this.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!