Find rows in which the first column is within a range defined by a value in another matrix.

I am extracting rows from matrix acc1, which have a first column value within a certain range . This range is defined by two values taken from a double, a. I am getting error messages for this and not sure why.
q=acc1(acc1(:,1) > a(1,1) & acc1(:,1)< a(2,1) , :);

5 Comments

That line looks like it'll do what you describe.
acc1 = randi(10,5,2);
a = [3; 7];
q=acc1(acc1(:,1) > a(1,1) & acc1(:,1)< a(2,1) , :);
disp(acc1);
5 6 8 8 10 9 4 3 5 6
disp(q);
5 6 4 3 5 6
So what error messages do you get?
Operator '>' is not supported for operands of type 'cell'.
How do I stop something being a cell? I used readcell to import data from an excel sheet, is there a better alternative? I would use readmatrix but matlab was saying that is now not reccomended.
As far as I know readmatrix is still recommended. Try that and see if the returned variable(s) is/are as you expect.

Sign in to comment.

Answers (0)

Products

Release

R2022a

Asked:

on 3 May 2022

Commented:

on 3 May 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!