Summing up two graphs with different starting point
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kushagra Mehrotra
le 16 Mar 2021
Commenté : Kushagra Mehrotra
le 16 Mar 2021
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
0 commentaires
Réponse acceptée
ANKUR KUMAR
le 16 Mar 2021
Modifié(e) : ANKUR KUMAR
le 16 Mar 2021
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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!