How to write matlab program for histogram with out using hist function.

5 ビュー (過去 30 日間)
REVU VARAPRASAD
REVU VARAPRASAD 2015 年 9 月 10 日
回答済み: Walter Roberson 2021 年 8 月 18 日
Xw = abs(fft(Xt));
ki = hist(Xw,L)%%%L=bin lenth,Xw=1000 randam samples

回答 (4 件)

Image Analyst
Image Analyst 2015 年 9 月 10 日
Hint: use a for loop over all the elements in your array. Convert the value of the array into a bin number. Then increment the "counts" array at that bin number:
for k = 1 : length(Xw(:))
binNumber = ...... (you do this part)
counts(binNumber) = counts(binNumber) + 1;
end
bar(counts, 'FaceColor', 'b');

Steven Lord
Steven Lord 2015 年 9 月 10 日
Easy. Call HISTCOUNTS or HISTOGRAM instead of HIST.

rodrigo figueiredo
rodrigo figueiredo 2021 年 8 月 18 日
編集済み: rodrigo figueiredo 2021 年 8 月 18 日
a[]=0;
for p =1 : ?? :length(Xt)
for k = 1 : floor(abs(fft(Xt)))
a= [a Xt]
end
end
nbins = 25;
h = histogram(a,nbins)
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 8 月 18 日
That code is a highly inefficient way of replicating the original Xt signal many times, and then taking a histogram of the repeated signal -- which is going to have the same relative portions as the original signal would have.
However, the original poster wants to take a histogram of the fft output, rather than having the mean() of the signal determine how many copies of the original signal to make.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2021 年 8 月 18 日
N = 1000;
L = 50; %number of bins, not bin width!
Xt = randn(1,N) + atan(pi*rand(1,N));
Xw = abs(fft(Xt));
figure
hist(Xw,L);
minXw = min(Xw);
maxXw = max(Xw);
binwidth = (maxXw - minXw)/L;
binnum = 1 + floor((Xw - minXw) / binwidth);
bincounts = accumarray(binnum(:), 1);
X = minXw + (0:L) * binwidth;
figure
bar(X, bincounts)
bar has minor differences in the default bar width; it would not be difficult to adjust.

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by