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

조회 수: 3 (최근 30일)
Don
Don 2023년 5월 22일
댓글: Don 2023년 5월 22일
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))

채택된 답변

Sulaymon Eshkabilov
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
...
  댓글 수: 2
Don
Don 2023년 5월 22일
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 2023년 5월 22일
Nevermind, I figured it out Thanks!
histogram('Categories',{'1','2','3'},'BinCounts',[N1 N2 N3])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by