matrix function that compare a list of real numbers with a real number
2 次查看(过去 30 天)
显示 更早的评论
I need a function which accepts as input a list of real numbers, and a real number X and which returns to the output:
• The number of how many times the number (X) appear in the table
• The location where this number appears in the table
• A table that will have the value 0 in the positions where (X) appears and the value -1 in the remaining positions
• A table(matrix) where the elements of the original matrix that is larger than the input number (X) will be replaced with the maximum number of the original table
• A vector which will contain all the unique elements of the input table which are larger than the number(X) we gave to the entrance.
2 个评论
回答(1 个)
Image Analyst
2012-11-19
OK. Do you have a question? Why don't you just use unique():
allTheNumbers = unique(X);
and then find out where they occur
mapOfNumber = (X == allTheNumbers(1)); % Find out where the first number occurs.
and so on.
If you have floating point numbers, not numbers of class "int32" or other integer types, be aware of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!