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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 18 Ott 2012
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 Commenti
tusu
tusu il 19 Ott 2012
thanx it works
what is the difference of histc and accumarray function reference to their operations?
Walter Roberson
Walter Roberson il 19 Ott 2012
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.

Accedi per commentare.

Più risposte (2)

Image Analyst
Image Analyst il 17 Ott 2012
Try this:
for k = 0 : 255
x = floor(k/16);
y = rem(k, 16);
fprintf('x = %d, y = %d\n', x, y);
end
  2 Commenti
tusu
tusu il 18 Ott 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 il 18 Ott 2012
Modificato: Image Analyst il 18 Ott 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)

Accedi per commentare.


Matt Fig
Matt Fig il 18 Ott 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 Commenti
tusu
tusu il 18 Ott 2012
Modificato: tusu il 18 Ott 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..
Image Analyst
Image Analyst il 19 Ott 2012
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?

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by