plot not displaying figure

조회 수: 1 (최근 30일)
Ram Basnet
Ram Basnet 2021년 5월 1일
i have table which has datetime and sub_metering_1 as two variables on table. I wrote code to plot the figure but it is not showing
if (data_useful.DateTime.Hour==8)
figure()
plot(DateTime, Sub_metering_1)
end
  댓글 수: 2
dpb
dpb 2021년 5월 1일
Your "if" is not getting executed -- IF is True iff all elements of the logical expression are true -- and you undoubtedly have data in the table that are not in the eighth hour as well as some that are.
It's not clear for sure what you do intend, but
is8=(data_useful.DateTime.Hour==8); % logical addressing for Hour==8
if any(is8) % will match if are any data at Hour==8
figure()
plot(data_useful.DateTime(is8), data_useful.Sub_metering_1(is8)) % plot the subset of data
end
While the above will (probably) work to do the one specific thing, it's generally bad practice to bury "magic" constants like the 8 above in code; use variables instead. Then you will be able to change the wanted hour to be plotted simply by changing some data, perhaps tying it to user input or an argument in a function even, without having to change the code itself.
Ram Basnet
Ram Basnet 2021년 5월 2일
isa==(data1.DateTime.Hour==8)
if any(isa)
meter_readings_cluster_few = data1.Sub_metering_1;
dates_table_few= data1.DateTime
end
plot(dates_table_few, meter_readings_cluster_few)

댓글을 달려면 로그인하십시오.

답변 (1개)

Saravanakumar Chandrasekaran
Saravanakumar Chandrasekaran 2021년 5월 2일
You are trying to a logical check for data_useful.DateTime.Hour==8. so at all times it is getting failed.
in the suggestion provided by dpb, you have wrongly included ==
i.e., the line should be
isa = (data1.DateTime.Hour==8)
i hope if u correct the above line ,it will work.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by