Histogram implementation in Matlab vs Perl

7 visualizaciones (últimos 30 días)
g
g el 6 de Ag. de 2014
Comentada: Image Analyst el 6 de Ag. de 2014
Hello,
I have perl code that reads in a file, line by line and creates a histogram by mapping the keys to a hash.
while (get line){
%hist1=map{$_=>0} @$column
}
How to do this in matlab? I have parsed the input with regexp/regexprep but now how I map this to an array?
Thanks.

Respuesta aceptada

Image Analyst
Image Analyst el 6 de Ag. de 2014
In the loop, after you've read the input values on the line into some array (which it sounds like you say you've done already):
counts = hist(yourArray, numberOfBins);
  2 comentarios
Image Analyst
Image Analyst el 6 de Ag. de 2014
g'a "Answer" moved here:
When I put counts = hist(yourArray, numberOfBins) inside the loop, it only keeps a copy of the last array not a cumulative count.
Image Analyst
Image Analyst el 6 de Ag. de 2014
Well what do you want? I thought you were just going to use it somehow inside the loop. Do you need to keep them all once the loop has ended and use them again? If so, index it:
counts{index} = hist(yourArray, numberOfBins); % Stick into cell array.
index = index + 1;
Or you can put into a regular numerical 2D array:
counts2d = ones(1, numberOfBins); % Put before the loop starts
In the loop:
counts2d(index, :) = hist(yourArray, numberOfBins); % Stick into one row.
index = index + 1;
I can't always read minds - you have to tell me exactly what you want.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by