Selecting range of data in a matrix
Show older comments
Hello,
I'm trying to create different groups from a matrix of dimensions 2784x1.
Data in the matrix range from 0100:9999. From those data I want to create group that have certain range like this :
A = 0100:0999
B = 1000:1499
Then from that, I would be able to create separate matrix for each of them.
Thank you,
Best regards.
Accepted Answer
More Answers (1)
Khalid Mahmood
on 7 Apr 2021
Edited: Khalid Mahmood
on 7 Apr 2021
%Generate M 2784x1 matrix of unformly distributed random intergers ranging from 100 to 9999
M=randi([100 9999],2784,1)
rangeA=[100 999]; %least and highest values belonging to A
indA=find(M>=rangeA(1) & M<=rangeA(2)) %find indices of values in range of A
A=M(indA); %Assign corresponding values in M to A
%Apply same procedure to range B
rangeB=[1000 1499]; %least and highest values belonging to B
indB=find(M>=rangeB(1) & M<=rangeB(2)) %find indices of values in range of B
B=M(indB); %Assign corresponding values in M to B
1 Comment
Khalid Mahmood
on 7 Apr 2021
code works fine. I comments of Last 3 lines change A to B
Categories
Find more on Bartlett 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!