MATLAB: Assign symbol for given range of data

assign valuedata

I have sequences
a=[1 5 3 5 5 2 12 7 14 2 11 11 5 7 7 3];
b=[0 0.1 3 0.8 0.8 5 5 7 7 0.56 0.56 1 1 0 3 4].
a has min 1, max 14 value and b has min 0, max 7 value. I want to make range for a and b and want to assign symbol for numbers falls in that particular range. i.e. for a range is 3 so 1-3,4-6,7-9,10-12,13-15 and for b range is 0.5 i.e. 0-0.5,0.5-1,1-1.5,…..,6.5-7. i.e.
1-3 4-6 7-9 10-12 13-15
0-0.5 p1 p2 p3 p4 p5
0.51-1 p6 p7 p8 p9 p10
1.01-1.5 p11 p13 p14 p15 p16
1.51-2 ................................
2.01-2.5 ................................
,......, ................................
6.5-7 ................................
i.e. numbers falls between a=1-3 and b=0-0.5 will assign value p1, numbers falls between a=4-6 and b=0.5-1 will assign value p2 and likewise. p1, p2,.. are symbols so they can be anything I want to take them as numbers i.e. p1=1, p2=2, p3=3,….
so here I write for 2 variables but I have data 4 variable and want to do this for 4 variable data so how to do for 4 variable data.
finally I want output which indicates that for particular number of a and b which symbol is assign i.e.
a b symbol
1 0 p1
5 0.1 p3
3 3 p7
5 0.8 .
5 0.8 .
2 5 .
12 5
7 7
14 7
2 0.56
11 0.56
11 1
5 1
7 0
7 3
3 4
so like this for 4 variable data, I used p1, p2,…. just to indicate as symbol but I want use symbol as numbers i.e. 1,2,3,…. i.e. 1,2,3,… instead p1,p2,…

Best Answer

Just define your ranges and have a 4-nested for loop and create a cell array
counter = 1;
for v1 = 1 : length(ranges1)
for v2 = 1 : length(ranges2)
for v3 = 1 : length(ranges3)
for v4 = 1 : length(ranges4)
% Assign the p string to the cell array.
ca{v1,v2,v3,v4} = sprintf('p%d', counter);
counter = counter + 1;
end
end
end
end