Need to change some (not all) values in a Histogram.
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sulaymon Eshkabilov
2023년 5월 22일
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
...
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!