show all rows where value in column 13 is equal to a specific number

7 次查看(过去 30 天)
Hi,
I know that I can display all elements of the first column of a matrix that are larger than 1500 by using this command:
find(data18(:,1)>1500);
However, I would like to find all the rows where the value in column 13 is equal to one and I tried this:
find(data18(:,13)==1);
From what I can see, this is not working. What is wrong with that code?
In addition, I would like to see not only the value in those columns where the value is equal to 1, but also from all other elements of that specific row

采纳的回答

Image Analyst
Image Analyst 2013-5-4
编辑:Image Analyst 2013-5-4
Probably because data18 is floating point, not integer. And in the second case you're checking for EQUALITY, while in the first case you were checking for "greater than." Please read and understand the FAQ on this topic: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
  3 个评论
Image Analyst
Image Analyst 2013-5-4
Try this:
% Create an array of random integers, from 1 to 8,
% in a 20 row by 9 column matrix.
data18 = int32(randi(8, [20,9]))
% Extract only column 9
column9 = data18(:, 9)
% Get a count of how many times each number,
% from 1 up to the max of column9, appears.
counts = histc(column9, 1:max(column9))
% Find out which integers have exactly 2 occurrences:
numbersOccurringTwice = find(counts == 2)
Sample run in the command window:
column9 =
4
4
1
1
8
5
3
3
2
2
3
3
7
4
4
2
8
6
7
6
counts =
2
3
4
4
1
2
2
2
numbersOccurringTwice =
1
6
7
8

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by