MATLAB Answers

How can I plot the mid-curve or interpolant between several curves?

조회 수: 1(최근 30일)
Leonardo Peretti
Leonardo Peretti 2021년 7월 19일
댓글: Mathieu NOE 2021년 7월 19일
Hello guys, I just started using Mathlab for a project i have to do. I have a series of curves (where the X represents the project completion of a project from 0 to 100% and the Y represent the costs of the project from 0 to 100%) and I already plotted them all in a graph. Now, what I have to do is find the mid curve between these lines and plot it in the same graph. I'd be very grateful if someone could help me. Thanks in advance
xBCA36 = [0:(100/32):100];
yBCA36 = [0 0 0.01 0.01 0.02 0.05 0.11 0.26 0.44 0.61 0.66 0.72 0.77 0.83 0.87 0.88 0.91 0.92 0.92 0.92 0.93 0.94 0.95 0.96 0.97 0.97 1 1 0.99 1 1 1];
xBCA08 = [0:(100/54):100];
yBCA08 = [0 0 0 0 0.01 0.05 0.08 0.13 0.19 0.3 0.38 0.54 0.62 0.7 0.73 0.8 0.84 0.87 0.89 0.9 0.92 0.93 0.94 0.95 0.96 0.96 0.96 0.97 0.98 0.98 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
xBCA12 = [0:(100/55):100];
yBCA12 = [0 0.01 0.03 0.05 0.07 0.14 0.23 0.33 0.37 0.42 0.49 0.53 0.57 0.61 0.65 0.68 0.7 0.73 0.76 0.77 0.8 0.82 0.83 0.84 0.85 0.87 0.88 0.89 0.89 0.9 0.91 0.92 0.93 0.94 0.94 0.96 0.96 0.97 0.98 0.99 0.99 0.99 0.99 0.99 1 1 1 1 1 1 1 1 1 1 1 1];
xBCA38 = [0:(100/22):100];
yBCA38 = [0 0 0.05 0.14 0.38 0.57 0.58 0.6 0.68 0.78 0.87 0.89 0.91 0.91 0.91 0.91 0.91 0.91 0.92 0.92 1 1 1];
xBNA07 = [0:(100/29):100];
yBNA07 = [0 0.01 0.01 0.03 0.04 0.07 0.08 0.12 0.19 0.28 0.45 0.54 0.63 0.68 0.71 0.75 0.78 0.82 0.83 0.84 0.85 0.88 0.9 0.92 0.92 0.94 0.96 0.98 0.99 1];

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 7월 19일
Hello Leonardo
this is my suggestion; to be able to do math between different sets of data (like doing the average) you have first to make sure that all samples are related to the same x axis vector. So here I created a new xc (c = common) x vector and did linear interpolation of the given data. then you can do all maths you want
NB : the xBCA36 and yBCA36 you post have a length difference of 1 , so to avoid this problem I simply added a zero at the beginning of yBCA36; maybe just an error of copy / paste ?
the code :
clc
clearvars
% xBCA36 = [0:(100/32):100];
% yBCA36 = [0 0 0.01 0.01 0.02 0.05 0.11 0.26 0.44 0.61 0.66 0.72 0.77 0.83 0.87 0.88 0.91 0.92 0.92 0.92 0.93 0.94 0.95 0.96 0.97 0.97 1 1 0.99 1 1 1];
xBCA36 = [0:(100/32):100];
yBCA36 = [0 0 0 0.01 0.01 0.02 0.05 0.11 0.26 0.44 0.61 0.66 0.72 0.77 0.83 0.87 0.88 0.91 0.92 0.92 0.92 0.93 0.94 0.95 0.96 0.97 0.97 1 1 0.99 1 1 1];
xBCA08 = [0:(100/54):100];
yBCA08 = [0 0 0 0 0.01 0.05 0.08 0.13 0.19 0.3 0.38 0.54 0.62 0.7 0.73 0.8 0.84 0.87 0.89 0.9 0.92 0.93 0.94 0.95 0.96 0.96 0.96 0.97 0.98 0.98 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
xBCA12 = [0:(100/55):100];
yBCA12 = [0 0.01 0.03 0.05 0.07 0.14 0.23 0.33 0.37 0.42 0.49 0.53 0.57 0.61 0.65 0.68 0.7 0.73 0.76 0.77 0.8 0.82 0.83 0.84 0.85 0.87 0.88 0.89 0.89 0.9 0.91 0.92 0.93 0.94 0.94 0.96 0.96 0.97 0.98 0.99 0.99 0.99 0.99 0.99 1 1 1 1 1 1 1 1 1 1 1 1];
xBCA38 = [0:(100/22):100];
yBCA38 = [0 0 0.05 0.14 0.38 0.57 0.58 0.6 0.68 0.78 0.87 0.89 0.91 0.91 0.91 0.91 0.91 0.91 0.92 0.92 1 1 1];
xBNA07 = [0:(100/29):100];
yBNA07 = [0 0.01 0.01 0.03 0.04 0.07 0.08 0.12 0.19 0.28 0.45 0.54 0.63 0.68 0.71 0.75 0.78 0.82 0.83 0.84 0.85 0.88 0.9 0.92 0.92 0.94 0.96 0.98 0.99 1];
xc = 0:1:100; % x common to all curves
yBCA36 = interp1(xBCA36,yBCA36,xc,'linear');
yBCA08 = interp1(xBCA08,yBCA08,xc,'linear');
yBCA12 = interp1(xBCA12,yBCA12,xc,'linear');
yBCA38 = interp1(xBCA38,yBCA38,xc,'linear');
yBNA07 = interp1(xBNA07,yBNA07,xc,'linear');
y_average = (yBCA36+yBCA08+yBCA12+yBCA38+yBNA07)/5; % LINEAR AVERAGE
plot(xc,yBCA36,xc,yBCA08,xc,yBCA12,xc,yBCA38,xc,yBNA07,xc,y_average,'k *-');
legend('yBCA36','yBCA08','yBCA12','yBCA38','yBNA07','AVERAGE');
And the result :

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by