필터 지우기
필터 지우기

How to fill area under the stairstep graph plot in MATLAB ?

조회 수: 6 (최근 30일)
Rufiya
Rufiya 2023년 8월 14일
댓글: Rufiya 2023년 8월 14일
Hi All,
Please could anyone help me fill the area under the stairstep graph plot created from the attached TestData.m file using the excel data sheet in the attached zip file.
I tried intially using the area function to fill the area under the stairstep graph, but unfortunately the graph output becomes too noiser and does not any longer represent as stairstep graph.
Thanks in advance and looking forward to hear from you.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 8월 14일
Hi,
Here is how you can solve this exercise (use your MS EXcel file, then no warnings will pop up!):
FZ = unzip('Final Filtered Catalogued Object Data - Copy.zip');
rawTable = readtable(FZ{1,1},'Sheet','Final Data');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
x = rawTable.ApogeeAltitude; %: get the excel column, ApogeeAltitude(Km) (header name)
y1 = rawTable.RocketBody; %: get the excel column, RocketBody (header name)
y2 = rawTable.Debris; %: get the excel column, Debris (header name)
y3 = rawTable.Payload; %: get the excel column, Payload (header name)
%%
figure;
s=stairs(x,y2);
s.Color = 'red';
set(gca, 'ylim', [0 100]);
set(gcf,'color','w');
grid on
grid minor
hold on
BB = min(s.YData);
X = [s.XData(1),repelem(s.XData(2:end),2)];
Y = [repelem(s.YData(1:end-1),2),s.YData(end)];
fill([X,fliplr(X)],[Y,BB*ones(size(Y))], 'y')

추가 답변 (0개)

카테고리

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