I need to plot 8 bit long 256 data in two dimension axis
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Okt. 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 Kommentare
Walter Roberson
am 19 Okt. 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.
Weitere Antworten (2)
Image Analyst
am 17 Okt. 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 Kommentare
Image Analyst
am 18 Okt. 2012
Bearbeitet: Image Analyst
am 18 Okt. 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)
Matt Fig
am 18 Okt. 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 Kommentare
Image Analyst
am 19 Okt. 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?
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!