Plots not showing data

12 ビュー (過去 30 日間)
Dillon Trimmell
Dillon Trimmell 2022 年 1 月 31 日
回答済み: Yash Srivastava 2022 年 2 月 3 日
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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by