I need to know how to organize a find statement into a set order with characters instead of it's number's. I want information to come out like below.

1 view (last 30 days)
A=[18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36];
volt=round(A);
%newscrip below
function [fruit_fin]=Program05b(volt)
B=[1:1:28]
O=[find(volt>=31 & volt<=40,28)]
G=[find(volt>=21 & volt<=30,28)]
P=[find(volt>=11 & volt<=20,28)]
A=[find(volt>=0 & volt<=10,28)]
U=[find(volt<0 | 40<volt,28)]
fruit_fin=[O,P,G,A,U]
end
% anwers % I know how to get it into a table.
18 P
33 O
31 O
34 O
15 P
37 O
10.5 P
48 U
50 U
38 O
35 O
39 O
42 U
33 O
31 O
1 A
5 A
9 A
13 P
11 P
27 G
35 O
-1 U
46 U
22 G
6 A
19 P
36 O

Accepted Answer

Steven Lord
Steven Lord on 13 Mar 2019
Edited: Steven Lord on 13 Mar 2019
discretize your data.
A=[18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 ...
31 1 5 9 13 11 27 35 -1 46 22 6 19 36];
volt=round(A);
edges = [-Inf 0 11 21 31 41 Inf];
bins = {'U', 'A', 'P', 'G', 'O', 'U'};
results = discretize(volt, edges, bins);
Elements in volt in the range [-Inf, 0) will map to 'U' in results. I tried to indicate that with spacing in the code above, where U is between -Inf and 0.
Elements in volt in the range [0, 11) will map to 'A' in results. The other bins behave similarly until you reach the last one.
The last bin is special. Elements in volt in the range [41, Inf] will map to 'U' in results. The last bin contains both its endpoints, not just the left one.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!