I need to plot 8 bit long 256 data in two dimension axis

Hello
I have 500 data with variation 0~255.Now I need to convert it in binary at first 8 bit long...like 0 is 0000 0000 and 255 as 1111 1111
Now on the X axis i shall put 0 to 15...and Y axis I shall put at 0 to 15 i.e I need to put in X axis from 0000 to 1111 same for Y axis 0000 to 1111 need to plot.
So how shall I put suppose no 227 ie in binary 11100011?

 Respuesta aceptada

y = mod(YourData, 16);
x = fix(YourData ./ 16);
scatter(x, y)
Notice I only did a 2D plot. You have not indicated what your Z value should be.
You have also not indicated what you want to have happen when multiple values map to the same (X,Y) coordinates, as must happen when you have more than 256 entries in your matrix.

11 comentarios

tusu
tusu el 18 de Oct. de 2012
Editada: tusu el 18 de Oct. de 2012
on z axis I have prob of occurrence of each number ranging o to 255,,suppose it 255 occurs 3 times among my total 500 data so prob of occurrence shall be 3/500 which I already have...so my md plot shall give the surface of prob of occurrence each no ranging o to 255.i.e how much time each no occurred among total 500 data. am i have to use scatter3..then how?
tusu
tusu el 18 de Oct. de 2012
yes walter hope u got my situation ,______" You have also not indicated what you want to have happen when multiple values map to the same (X,Y) coordinates, as must happen when you have more than 256 entries in your matrix." if multiple values map on same (x,y) then it shall reflect on z,,,the prob of occurrence, now I shall turn it into z..i have values of z and x,y individually but How I manage this 3d plot for all my 500 data
y = mod(YourData, 16);
x = fix(YourData ./ 16);
z = accumarray([x(:), y(:)], 1) ./ numel(x);
surf(x,y,z);
tusu
tusu el 18 de Oct. de 2012
Editada: tusu el 18 de Oct. de 2012
Hello as per my requiremnt I am writing something like this but I am not getting surface like view in 3d or my desired result tell me where the error lies
c=1;
lpart=zeros(1,256);
rpart=zeros(1,256);
for i=1:1:255
lpart(c)=mod(i,16)
rpart(c)=fix(i ./16)
c=c+1;
end
X = randi(256,1,500)-1;
P= histc(X,0:255)/length(X);
[(0:255).' P(:)]
plot3(lpart,rpart,P);
grid on;
xlabel('Left Part')
ylabel('Right Part')
zlabel('Probability occurance')
i need a surface view in 3d plot for this but mesh or surf giving error, asking for same length
tusu
tusu el 19 de Oct. de 2012
hello
where the error lies? is the mapping of value of x and y axis to z axis is correct
You could build that lpart and rpart by using
[lpart, rpart] = ndgrid(0:15);
lpart = lpart(:);
rpart = rpart(:);
Your line
[(0:255).' P(:)]
has no obvious use.
If you want to construct your count array with histc instead of accumarray, you will need to reshape(P,16,16) to use it.
tusu
tusu el 19 de Oct. de 2012
Editada: tusu el 19 de Oct. de 2012
thank you for reply
Actually my problem remains on plotting the data using X axis and Y axis,,,at first I am generating random no ranging 0 to 255 by X = randi(256,1,500)-1;
then calculating its prob of occurence evry thing fine till this but..I am not able to translate my ide a into matlab code..I want each of my 500 data shall be plotted using X and Y axis,ie.e my data suppose 231 shall be plotted such that X axis is plotting 14 the (right 4 bit, 1110) and Y axis shall plot 7 (left 4 bit,0111) so as whole in x & Y surface i shall get 231 as 1110 0111 and on z axis I shall put how many times 231 occurrence in my random 500 no sequence.
the problem here is my X axis and Y axis shall be of 0 to 15, and z shall be 0 to 255 so I cam use surf or mesh if X cross y =z dimension but here in my code I am getting dimension of X axis is 256 Y axis is 256 so cant plot surface on z..I am not sure how much idea shall be possible in matlab..is it at all possible to represent a 8 bit data, in a plane by taking 4 bit from X axis and 4bit from Y...??
tusu
tusu el 19 de Oct. de 2012
any suggestions? where my concept creating error
You seem to be confused about whether Z should be probability of occurance, or number of occurrences.
YourData = randi(256,1,500)-1;
y = mod(YourData, 16);
x = fix(YourData ./ 16);
z = accumarray([x(:), y(:)]+1, 1) ./ numel(x);
surf(0:15,0:15,z);
tusu
tusu el 19 de Oct. de 2012
thanx it works
what is the difference of histc and accumarray function reference to their operations?
histc() always produces a vector result, and the first output is always counts. accumarray() can produce a multi-dimensional output, and is quite flexible about what values are worked with and what operation is done with the values.

Iniciar sesión para comentar.

Más respuestas (2)

Try this:
for k = 0 : 255
x = floor(k/16);
y = rem(k, 16);
fprintf('x = %d, y = %d\n', x, y);
end

2 comentarios

tusu
tusu el 18 de Oct. de 2012
my question is how can 8 bit data be represented along X-axis and Y axis by taking 4 bit each of it from 8 bit?
Image Analyst
Image Analyst el 18 de Oct. de 2012
Editada: Image Analyst el 18 de Oct. de 2012
I showed you how to get the upper 4 bits and lower 4 bits as a number that you can use as x and y to do your plotting. I thought this was what you wanted. Of course you could also display those values in binary strings rather than decimal in the tick marks if you wanted, but that's just a tick mark labeling issue and doesn't help at all with getting actual x and y values to do your plotting with.
% Generate 500 data points with random values in the range 0-255.
data = randi(255, [20 25]);
% Make a 2D array where we'll put a spot at the location
% where x = a number representing the upper 4 bits of the data value.
% and y = a number representing the lower 4 bits of the data value.
% Preallocate an output array
outputArray = zeros(16, 16, 'uint8');
for p = 1 : numel(data)
% For each data point...
grayLevel = data(p); % Get the value of the data
x = floor(grayLevel/16); % Get the x value.
y = rem(grayLevel, 16); % Get the y value.
fprintf('data(p) = %d, x = %d, y = %d\n', ...
grayLevel, x, y);
% Mark this place with a white pixel.
outputArray(y+1, x+1) = 255;
end
% Display the result.
imshow(outputArray, 'InitialMagnification', 5000)

Iniciar sesión para comentar.

Matt Fig
Matt Fig el 18 de Oct. de 2012
I have no idea how your data is structured. So I will leave that to you and just show how to label the axes.
x = 1:10;
y = x.^2;
plot(x,y)
% Now set the axes-label to binary, using 4 and 8 bits.
set(gca,'xticklabel',dec2bin(get(gca,'xtick'),4))
set(gca,'yticklabel',dec2bin(get(gca,'ytick'),8))

2 comentarios

tusu
tusu el 18 de Oct. de 2012
Editada: tusu el 18 de Oct. de 2012
my data is simple in matrix structure like [o,1,2,............127,248,255] now I want to plot my data i.e say 255 (in binary 1111 1111) using two axis,So my idea is X will plot 1111 i.e i shall choose the point representing 1111 form x axis and Y axis shall plot next 1111 and same for Y..so in a 3d plot...if I draw a line form X axis and from Y axis then cut point in the surface present 255..hope u got it..
I thought my code did that. If you want "3D" you could always use surf() instead of imshow. Anyway, what is the real reason you want to do this unusual thing?

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 17 de Oct. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by