Finding equal values, between values, greater than and lesser than values of a matrix based on some values

1 回表示 (過去 30 日間)
Hi. Suppose I have matrix A of size (m*n) e.g.
A = [12 44
93 43
128 44
145 41
180 41
220 40
280 40];
and the a,b,c and d values e.g.
a = 10
b = 95
c = 145
d = 290
As you know
a < A(1,1)
A(2,1) < b < A(3,1)
c = A(4,1)
d > A(7,1)
I want Matlab to do above process and search the a,b,c and d values in the A(:,1) and tell me that the a,b,c and d values are lesser than or greater than or equal or lying between what members of A(:,1).
Thanks for your help.
  4 件のコメント
James Tursa
James Tursa 2017 年 11 月 7 日
You did not answer my request. Please provide the exact variable outputs you would like based on your example. I.e., at the end of your code, what variables would you like as output and what specific values would they contain for your example above?
mr mo
mr mo 2017 年 11 月 7 日
編集済み: mr mo 2017 年 11 月 7 日
for this example I want to reach these outputs if we consider that the a,b,c,d values are given to the code respectively, so I want these out puts respectively:
0 12
93 128
145
280 1000
which means a is lesser than 12 and b is between 93 and 128 and c is equal to 145 and d is between 280 and 1000.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 7 日
A = [12 44
93 43
128 44
145 41
180 41
220 40
280 40];
a = 10;
b = 95;
c = 145;
d = 290;
ii_interval_of_1st_column_of_A = discretize([a,b,c,d],[-inf;A(:,1);inf]);
  12 件のコメント
mr mo
mr mo 2017 年 11 月 8 日
Thank you very much. This code works very well now.
mr mo
mr mo 2017 年 12 月 18 日
編集済み: mr mo 2017 年 12 月 18 日
@Andrei Bobrov: Hi. Thanks again for your help.
I run your above code in my matlab m-file and I must run this code in for loops, but this code is taking to much running time.
For example I run the for loops 5 times and its running time is given by Run and Time tool in Matlab in the below image.
The red digits are showing the running time of that line in second.
I must run your code 1000 times and the running time will be more than 10 hours.
Is there any possibilities to change this code to decreasing the running time?
Thanks you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by