Plots not showing data

10 次查看(过去 30 天)
Dillon Trimmell
Dillon Trimmell 2022-1-31
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);
(same for figure 3)
thanks for the help.
  1 个评论
Arif Hoq
Arif Hoq 2022-1-31
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);

请先登录,再进行评论。

回答(1 个)

Yash Srivastava
Yash Srivastava 2022-2-3
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.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by