Filter löschen
Filter löschen

Convert for loop to matrix operation

2 Ansichten (letzte 30 Tage)
Bernhard Petri
Bernhard Petri am 29 Mär. 2023
Beantwortet: daniel mitchell am 29 Mär. 2023
I have loaded an image, created a histogram for it and would like to convert this for loop to matrix operation, how would I do that?
h1 = histogram(img1, edges, 'normalization','probability');
cdf = zeros(1, h1.NumBins);
sum_value = 0;
for i = 1:h1.NumBins
sum_value = sum_value + h1.Values(i);
cdf(i) = (h1.NumBins-1)*sum_value;
end
  1 Kommentar
Antoni Garcia-Herreros
Antoni Garcia-Herreros am 29 Mär. 2023
Hello,
You can try using cumsum
sum_value=sum(h1.Values); %This will be always 1 if you use the normalitzation probability in your histogram
cdf=cumsum(h1.Values).*(h1.NumBins-1);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

daniel mitchell
daniel mitchell am 29 Mär. 2023
perhaps this is the solution you are looking for?
h1 = histogram(randn(1e7,1), 'normalization','cdf','DisplayStyle','stairs');
cdf = h1.Values;

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by