Need to change some (not all) values in a Histogram.

2 visualizaciones (últimos 30 días)
Don
Don el 22 de Mayo de 2023
Comentada: Don el 22 de Mayo de 2023
I have some counts in a histogram that need to be divided by a number; most counts are fine as gathered. I have tried to use switch /case and if / then but no luck. I can change all of the counts easily but my knowledge of Python and Matlab is not great. FWIW, this is simply counting the number of times the numbers 1-9 are in my data, My attempts don't produce errors but they don't work either : ).
keyPress = thingSpeakRead(readChannelID,'Fields',keyID,...
'NumDays',365,'ReadKey',readAPIKey);
[counts, bin] = histcounts(keyPress);
% This will divide all counts by two.
countActual = counts / 2;
% Converting to string and using Case doesn't work.
stringBin=num2str(bin)
switch (stringBin)
case 9
countActual = counts/4;
case '8'
countActual = counts/8;
case "7"
countActual = counts/16;
end
% This doesn't change the value for counts of 9 either.
if bin == 9
countActual = counts/4;
end
h = histogram('BinEdges',bin,'BinCounts',countActual)
h.Orientation = 'horizontal';
E = h.BinEdges;
y = h.BinCounts;
yloc = E(1:end-1)+diff(E)/2;
text(y-4,yloc, string(y))

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 22 de Mayo de 2023
You can use simply this:
N1 = sum(DATA==1); % How many 1s in Data
N2 = sum(DATA==2); % How many 2s in Data
N3 = sum(DATA==3); % How many 1s in Data
...
  2 comentarios
Don
Don el 22 de Mayo de 2023
Thanks! I'm sure I can manipulate them from there but I'm not sure how to get N1 N2 and N3 into histogram form though. I need that one extra line of code, my fiddling has not produced any results.
Don
Don el 22 de Mayo de 2023
Nevermind, I figured it out Thanks!
histogram('Categories',{'1','2','3'},'BinCounts',[N1 N2 N3])

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by