How to plot multiple vectors of a dateset in a single figure window?

조회 수: 3 (최근 30일)
RP
RP 2019년 11월 10일
답변: Anmol Dhiman 2019년 11월 13일
Dear Matlab-users,
Herewith I have attached my datafile. I am explaining my problem on the basis of that datafile.
The file contains 9 columns namely Date, A1, B1, C1, D1, A2, B2, C2, and D2. The date column remain same for all variables. For A1, B1, C1, and D1, I need 2-D line plot, and for A2, B2, C2, and D2, I need line plot with error bar.
Here, I want two types of merged plots as follows where the common Date column should be in the X-axis in each plot.
  1. First, I need to merge 2 respective plots in the same date axis. For instance, A1 line plot, and A2 line plot with error bar need to be presented in one date axis. Similarly, B1-B2 should be merged in another date axis, and similar with C1-C2, and D1-D2. Therefore, one should have total four merged plots at the end.
  2. Then, I need to arrange the four merged plots in one figure window.
I tried both hold on, and subplot option to merge plots in one axis and in one figure window respectively, but unable to do that as I am new to Matlab.
Please help me in this regard.
Thank you very much for your time.
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 10일
편집: KALYAN ACHARJYA 2019년 11월 10일
Hello,
You can load the xlsx file and plot accordingly, is there any issue?
Here for data selection.
RP
RP 2019년 11월 10일
But, how to set algorithm for both types of merging of all plots?
Please help.
Thank you.

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

답변 (1개)

Anmol Dhiman
Anmol Dhiman 2019년 11월 13일
You may find below code useful for plotting in the format that is mentioned
file_csv = readtable('SP.xlsx');
figure;
s1 = subplot(2,2,1);
plot(s1,file_csv.Date,file_csv.A1,file_csv.Date,file_csv.A2);
hold on
bar(s1,file_csv.Date,file_csv.A2);
s2 = subplot(2,2,2);
plot(s2,file_csv.Date,file_csv.B1,file_csv.Date,file_csv.B2);
hold on
bar(s2,file_csv.Date,file_csv.B2);
s3 = subplot(2,2,3);
plot(s3,file_csv.Date,file_csv.C1,file_csv.Date,file_csv.C2);
hold on
bar(s3,file_csv.Date,file_csv.C2);
s4 = subplot(2,2,4);
plot(s4,file_csv.Date,file_csv.D1,file_csv.Date,file_csv.D2);
hold on
bar(s4,file_csv.Date,file_csv.D2);
Also I have attached the figure.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by