Plots not showing data
9 views (last 30 days)
Show older comments
I am plotting 2 figures.
figure 2 is plotting 2 (1,12) arrays.
figure 3 is plotting 2 (1,365) arrays.
for some reason there is no data in the plots despite the limits on the axis being correct.
here is what my code looks like
Month{1}=Electricity(1:744);
Month{2}=Electricity(745:1416);
Month{3}=Electricity(1417:2160);
Month{4}=Electricity(2161:2880);
Month{5}=Electricity(2881:3624);
Month{6}=Electricity(3625:4344);
Month{7}=Electricity(4345:5088);
Month{8}=Electricity(5081:5832);
Month{9}=Electricity(5833:6552);
Month{10}=Electricity(6553:7296);
Month{11}=Electricity(7297:8016);
Month{12}=Electricity(8017:8760);
figure(2);
for i=1:12
MonthSum(i)=sum(Month{i});
plot((i),MonthSum(i))
hold on
end
hold off
z=1;
figure(3)
for j=1:365
Daily{j}=Electricity(z:z+23);
z=z+length(Daily{j});
DailySum(j)=sum(Daily{j});
end
x1=linspace(1,365,365);
y1=DailySum(:);
plot(x1,y1);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/880175/image.png)
(same for figure 3)
thanks for the help.
1 Comment
Arif Hoq
on 31 Jan 2022
how about this...
clear;
clc;
Electricity=randi(100,8760,1);
Month{1}=Electricity(1:744);
Month{2}=Electricity(745:1416);
Month{3}=Electricity(1417:2160);
Month{4}=Electricity(2161:2880);
Month{5}=Electricity(2881:3624);
Month{6}=Electricity(3625:4344);
Month{7}=Electricity(4345:5088);
Month{8}=Electricity(5081:5832);
Month{9}=Electricity(5833:6552);
Month{10}=Electricity(6553:7296);
Month{11}=Electricity(7297:8016);
Month{12}=Electricity(8017:8760);
figure(2);
for i=1:12
MonthSum(i)=sum(Month{i});
plot((i),MonthSum(i),'*')
hold on
end
hold off
z=1;
figure(3)
for j=1:365
Daily{j}=Electricity(z:z+23);
z=z+length(Daily{j});
DailySum(j)=sum(Daily{j});
end
x1=linspace(1,365,365);
y1=DailySum(:);
plot(x1,y1);
Answers (1)
Yash Srivastava
on 3 Feb 2022
Hi Dillon,
It is my understanding that you are trying to plot coordinates of month number and "MonthSum" on x and y-axis respectively.
The plot function, by default plots a line which requires at least two points in the form of vector. You may specify "Marker" type as shown below to plot individual point coordinates:
plot((i),MonthSum(i),"o");
You may refer to the following documentation to know more about "Marker" types.
I hope it helps you.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots 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!