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.?
Walter Roberson
Walter Roberson 2017 年 10 月 3 日
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..
Walter Roberson
Walter Roberson 2017 年 10 月 3 日
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 Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by