I have 3-hours data interval for 1 day data. How do i plot a bar graph in matlab?
Show older comments
Help, I need to plot a bar/histogram graph exactly like this website https://www.spaceweatherlive.com/en/archive/2012/05/12/kp.html using Matlab coding.
For briefing, we assume the file name is Kp Value. The Kp Value file will consist of 30 days of 3-hours interval data. For example, 0-3 UT, 3-6 UT, 6-9 UT, ..., 21-24 UT. Therefore, one (1) day data should have 8 bar in one graph. You get what i mean? (You can refer at the link as well).

So now, i want to add 10 days data in one graph where in my task, my date is from 2015-05-12 until 2015-05-22 (exactly ten (10) days). Below i attached the Kp Value file (Kp20150516.txt) for one month of 05-2015 to ploting the bar/histogram bar which I just want to grab the 10 days data (which consists of 3-hours interval data) from 2015-05-12 until 2015-05-22 as i mentioned before from the file name Kp20150516.txt.
This is my idea but it shows the whole 30 days data. It get messy.
Kp = load('Kp20150516.txt');
date_h=find(and(UT1h>=datenum(2015,05,12,0,0,0),UT1h<datenum(2015,05,21,24,0,0)));
bar(UT1h(date_h),Kp(:,8),0.8,'stacked'); %Kp(:,8) column 8 is the exactly value of Kp.
datetick('x','dd','keeplimits')
ylabel('Kp Index');
xlabel('Days');
This is the graph that i get messy.

Since i want to combine 2 plot in one graph, the value should be 240x1 double and each days must have only 8 bars. Otherwise, it shows error like this
Error using plot
Vectors must be the same length.
Error in Lemah (line 57)
plot(UT1h(date_h),Kp(:,8),'LineWidth',1.2)
Thank you!
7 Comments
MUHAMMAD
on 17 Dec 2022
Suvansh Arora
on 19 Dec 2022
In order to understand this better, I would need the following information:
- MAT file that defines UT1h and date_h and other variables used in the script.
Walter Roberson
on 2 Jan 2023
The attached file is about 15 kilobytes.
The sharepoint file (not attached) is large, but when I click through the download procedure on the linked page, and save to a local drive, then MATLAB is able to open the file as a .mat file.
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
