assign symbol for given range of data
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jay Hanuman
el 26 de Dic. de 2016
Comentada: Jay Hanuman
el 28 de Dic. de 2016
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,...
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Dic. de 2016
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
7 comentarios
Image Analyst
el 27 de Dic. de 2016
Try this:
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];
maxAIndex = ceil(max(a)/3)
fprintf(' a b symbol aIndex bIndex\n');
for k = 1 : length(a)
aIndex = ceil(a(k)/3);
bIndex = ceil(b(k)/0.5);
% handle special case of 0
if bIndex == 0
bIndex = 1;
end
symbol(k) = (bIndex-1) * maxAIndex + aIndex;
fprintf('%2d %.2f %3d, %8d %8d\n', a(k), b(k), symbol(k), aIndex, bIndex);
end
a b symbol aIndex bIndex
1 0.00 1, 1 1
5 0.10 2, 2 1
3 3.00 26, 1 6
5 0.80 7, 2 2
5 0.80 7, 2 2
2 5.00 46, 1 10
12 5.00 49, 4 10
7 7.00 68, 3 14
14 7.00 70, 5 14
2 0.56 6, 1 2
11 0.56 9, 4 2
11 1.00 9, 4 2
5 1.00 7, 2 2
7 0.00 3, 3 1
7 3.00 28, 3 6
3 4.00 36, 1 8
Más respuestas (0)
Ver también
Categorías
Más información sobre Numbers and Precision en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!