Summing up two graphs with different starting point

5 次查看(过去 30 天)
Hey Matlab Community,
I have two graphs as seen from the figure below and I need to sum them up.
For the graph I have 4 separate column vectors. So for Red I have two separate column vectors with X and Y values and similarly for Blue I have two separate X and Y values The challenge is they both start from different point. The Red one starts at 25C and the Blue one starts at 170C. How can I plot the sum of graphs ? ( Just to clarify the resulting graph should be exactly equal to red graph until 170C and then it would start to deviate because of the addition of Blue.)
I hope I managed to explain the challenge I am facing. Any help would be greatly appreciated.
Thanks and Greetings
Kush

采纳的回答

ANKUR KUMAR
ANKUR KUMAR 2021-3-16
编辑:ANKUR KUMAR 2021-3-16
Method 1: Using boolean
clc
clear
YY=rand(151,2);
XX=[[50:5:800]' [175:5:925]']
data=[XX(:,1) YY(:,1) XX(:,2) YY(:,2)]
plot(data(:,1), data(:,2),'k');
hold on
plot(data(:,3), data(:,4),'b');
uniq=unique([data(:,1);data(:,3)]);
for kk=1:length(uniq)
index1=find(data(:,1)==uniq(kk));
if ~isempty(index1)
value1(kk)=data(index1,2);
else
value1(kk)=nan;
end
index2=find(data(:,3)==uniq(kk))
if ~isempty(index2)
value2(kk)=data(index2,4);
else
value2(kk)=nan;
end
end
hold on
plot(uniq,value1+value2,'r')
Method 2: Interpolation
clc
clear
% generating random data
YY=rand(151,2);
XX=[[50:5:800]' [175:5:925]']
data=[XX(:,1) YY(:,1) XX(:,2) YY(:,2)]
plot(data(:,1), data(:,2),'k');
hold on
plot(data(:,3), data(:,4),'b');
uniq=unique([data(:,1);data(:,3)]);
value1=interp1(data(:,1),data(:,2),uniq);
value2=interp1(data(:,3),data(:,4),uniq);
plot(uniq,value1+value2,'r')
  1 个评论
Kushagra Mehrotra
Kushagra Mehrotra 2021-3-16
Ohh wow, this is incredible !
Thank you so much for taking time out and writing a code to help me, you are a saviour ! I will try to run the code and Accept the answer ASAP. Again thanks for the time you took to formulate that !

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by