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

4 ビュー (過去 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 Center および File ExchangeHistograms についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by