필터 지우기
필터 지우기

Plots not showing data

조회 수: 9 (최근 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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by