Let given array A with 512*512 elements are (here one sample of 4*4 is given)
5 4 6 8
9 11 30 34
12 13 13 14
how to plot a graph where x-axis contains the values of individual elements of 512*256 matrix and y-axis contain the frequency of the difference value. The frequency of difference value can be obtained as
1 -2
-2 -4
-1 -1
here the difference value can be found by subtracting the 2 consecutive elements in a row.Now suppose the original matrix A is 512*512 elements, then the difference matrix will be 512 * 256 elements.
Kindly suggest

댓글 수: 5

KSSV
KSSV 2017년 10월 3일
Do you have any pictorial example?
Walter Roberson
Walter Roberson 2017년 10월 3일
A(:, 1:2:end) - A(:,2:2:end) would give you a 512 x 256 array.
You have not indicated why the output should only be 256 rows.
aditya sahu
aditya sahu 2017년 10월 3일
I m really sorry ...the output should be 512 * 256 only..
aditya sahu
aditya sahu 2017년 10월 3일
ok..by doing A(:, 1:2:end) - A(:,2:2:end) gives 512 x 256 array. Then how can i plot a graph with x-axis as its elements of 512*256 array and y-axis as its frequency of occurence.
aditya sahu
aditya sahu 2017년 10월 3일
@ KSSV SIR, I HAVE ATTACHED A SAMPLE FILE THE PLOT SHOULD COME OR LOOKS LOOKS LIKE THIS.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 3일

0 개 추천

B = A(:, 1:2:end) - A(:,2:2:end);
histogram(B, 'binmethods', 'integers')
Note: this might require a fairly recent MATLAB (I do not recall ever having seen that option before.)

댓글 수: 9

aditya sahu
aditya sahu 2017년 10월 3일
Dear sir, when i use, histogram(B, 'binmethods', 'integers') The error is comming as Undefined function 'histogram' for input arguments of type 'uint8'. Kindy tell what has to be done now.?
Histogram was introduced in R2014b, and has always supported uint8. On the other hand, subtracting uint8 data can never give you negative values, so even if you were using a new enough version then for uint8 data you should use
B = double(A(:, 1:2:end)) - double(A(:,2:2:end));
For versions older than R2014b:
bins = min(B(:)) : max(B(:));
hist(B, bins);
aditya sahu
aditya sahu 2017년 10월 3일
편집: aditya sahu 2017년 10월 3일
Dear @ Walter Roberson thank for your help. but the below code is working.But only problem is in x-axis i want to limit it to (-40 to 40) ..can you help to sort this issue.
z=double(int32(A(:, 1:2:end))) - double(int32((A(:,2:2:end))))
[a,b]=hist(z,unique(z));
out=[b' sum((a),2)]
x=out(:,1);
y=out(:,2);
plot(x,y,'--bo')
Walter Roberson
Walter Roberson 2017년 10월 3일
편집: Walter Roberson 2017년 10월 3일
z = double(A(:, 1:2:end)) - double(A(:,2:2:end));
bins = -40:40;
N = histc(z, bins);
x = bins;
y = N;
plot(x, y, '--bo')
aditya sahu
aditya sahu 2017년 10월 3일
편집: Walter Roberson 2017년 10월 3일
No sir your code is giving incorrect plot ..kindly tell in my code how can i restrict the x-axis range to -40 to 40.The code is
z=double(int32(b(:, 1:2:end))) - double(int32((b(:,2:2:end))));
[a,c]=hist(z,unique(z));
out=[c' sum((a),2)];
x=out(:,1);
y=out(:,2);
plot(x,y, '--bo')
aditya sahu
aditya sahu 2017년 10월 3일
편집: Walter Roberson 2017년 10월 3일
ya..i got it...
plot(x(x>-40 & x<40), y(x>-40 & x<40),'or')
..is it right..
why are you converting to int32 before converting to double??
z = double(A(:, 1:2:end)) - double(A(:,2:2:end));
bins = -40:40;
N = histc(z(:), bins);
x = bins;
y = N;
plot(x, y, '--bo')
aditya sahu
aditya sahu 2017년 10월 4일
Thank you dear @ Walter Roberson.. Actually not required,but i have taken two different matrices where one is in uint8 and other is double. thats i have brrought back both to unit32..Thats all only.
Walter Roberson
Walter Roberson 2017년 10월 4일
It is not a problem to use double() on an array that is already double(), so leave out the conversion to int32()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2017년 10월 3일

댓글:

2017년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by