I need to plot 8 bit long 256 data in two dimension axis
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2012년 10월 18일
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
Walter Roberson
2012년 10월 19일
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.
추가 답변 (2개)
Image Analyst
2012년 10월 17일
Try this:
for k = 0 : 255
x = floor(k/16);
y = rem(k, 16);
fprintf('x = %d, y = %d\n', x, y);
end
댓글 수: 2
Image Analyst
2012년 10월 18일
편집: Image Analyst
2012년 10월 18일
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
2012년 10월 18일
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
Image Analyst
2012년 10월 19일
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?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!