Can Matlab handle segmented graphs and automatic trendlines?

조회 수: 1 (최근 30일)
Cynthia Moore
Cynthia Moore 2020년 3월 11일
댓글: Ronald Ssembajwe 2022년 11월 5일
I am looking to get a graphing application and Matlab is my top candidate at the moment. My immediate need is to generate graphs for my blood glucose readings, which I take twice daily. I would like to generate a graph something like the one below. This one has 3 segments. Each segment is two weeks long during which the medication dose (insulin) was constant. There are 6 graphs in all, each from a table of values. For each graph, there is a trend line (best fit linear reghression equation).
Here are my questions, can Matlab:
  1. Put these 6 (or more) equations on the same graph?
  2. Label the X axis with dates (1/06 1/08 1/10 etc.) instead of the numbers I show here?
  3. Read the values from an external table, like in Excel, so that is I update the table, the graph is automatically updated?
  4. Generate the trendlines automatically so that if the underlying data changes, a new trendline is created?
One last question: Can Matlab add shading to sections of the graph as in this example? This is a poor example, but it's the best I can do with my current software. I'm hoping Matlab can do better.

채택된 답변

Jakob B. Nielsen
Jakob B. Nielsen 2020년 3월 11일
The answer to all four questions is yes.
You can execute several plots in the same figure, as well as on the same axes (axes is what matlab calls what you would call a graph ;). If you have your date data in X, and your glucose readins in Y1, Y2 and Y3, say, you can either;
bloodplot=axes;
plot(bloodplot,X,Y1,X,Y2,X,Y3);
or simply
plot(X,Y1);
hold on %the hold on function causes new plots to be added to the current figure rather than replacing.
plot(X,Y2);
plot(X,Y3);
In regards to dates on the x axis, type doc datetick in the command window to open the documentation for datetick.
Basic functions like xlsread can read data from Excel sheets, and there are plenty of builtin functions to add trend lines to plots.
  댓글 수: 2
Cynthia Moore
Cynthia Moore 2020년 3월 11일
Thanks very much. I'm sold. I'll be purchasing a license and getting to work!
Ronald Ssembajwe
Ronald Ssembajwe 2022년 11월 5일
I still don't understand why the OP marked this as answer. 'cause it only seems to attempt 20 percent of the entire qn/querry.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by