Summing up two graphs with different starting point
9 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/552527/image.jpeg)
Thanks and Greetings
Kush
0 个评论
采纳的回答
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!