Help us understand the problem. What is going on with this article?

ThingSpeakの積み上げグラフ

以前書いた気温のグラフがバグってたので直してみました。二値の積み上げグラフで、片方を白にして消して、高気最低最温の表示を行います。

以前作ったものは0度以下に対応していませんでした。

% Last week max and min temputure

readChannelID = ;
readAPIKey = "";

last = 7 * 4;

day = datetime('now') - last;
disp(day);

% startdaystr = "Sep 22, 2019 00:00:00";
% enddaystr = "Sep 23, 2019 00:00:00";

for c = 1:last

    startdaystr = datestr(day,'mmm dd, yyyy 00:00:00');
    enddaystr = datestr(day + 1,'mmm dd, yyyy 00:00:00');
    [a,b] = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields',2,'DateRange', [datetime(startdaystr),datetime(enddaystr)]);

    a = filloutliers(a,'linear');
    [m, n] = max(a);
    [x, y] = min(a);

    t(c) = day;
    if x > 0
      vmax(c) = m - x
      vmin(c) = x
    elseif m > 0
      vmax(c) = m
      vmin(c) = x
    else
      vmax(c) = x - m
      vmin(c) = m
    end
    day = day + 1
end

C = vertcat(vmin, vmax);

H = bar(t, C, 'stacked');

ba = H(1);
bb = H(2);
disp(ba);

ba.FaceColor = 'flat';
bb.FaceColor = 'flat';

set(H(1),{'EdgeColor'},{[1 1 1]});
set(H(2),{'EdgeColor'},{[1 1 1]});
for c = 1:last
    if vmin(c) > 0 
      ba.CData(c,:) = [1 1 1];
      bb.CData(c,:) = [1 0 1];
    elseif vmax(c) < 0
      ba.CData(c,:) = [1 1 1];
      bb.CData(c,:) = [1 0 1];
    else
      ba.CData(c,:) = [1 0 1];
      bb.CData(c,:) = [1 0 1];
    end
end

スクリーンショット 2020-02-16 13.39.33.png

テストケース:最高気温10度最低気温2度

スクリーンショット 2020-02-16 13.35.22.png

テストケース:最高気温2度最低気温-10度

スクリーンショット 2020-02-16 13.34.28.png

テストケース:最高気温-2度最低気温-10度

スクリーンショット 2020-02-16 13.33.19.png

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした