Need to change some (not all) values in a Histogram.
3 views (last 30 days)
Show older comments
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))
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 22 May 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
...
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!