Hello
I have done 2 plots(see attached files) Now I need to sum my the 2 curves in one graph. As a result it should be one curve with y axis values added to each other. Such as in the year 45 1 graph y value 87,2 graph y value 80. So my new value should appear as 167.
Thanks a lot!

 Accepted Answer

It appears to me you only need a single y axes as the two plots appear to have the same range. To get two line plots on the same axes,
plot(....) %draw the first one
hold on
plot(....) %draw the second one
hold off

11 Comments

Thanks Walter, sorry my explanation was not good. I need sum 2 y datas. if I do as you told I will get 2 curve in 1 graph, but I need 1 curve.(summing two y curve datas)
Are the x and y values known, or do they need to be extracted from the graphic?
Are the x values the same for the parts that overlap, from roughly about 6 to 49?
How do you want to handle the left and right edges of the second graph, which extend further than the first graph? I estimate that from about 3.5 to 6 on the left and about 49 to 50 on the right has no corresponding data shown on the upper graph.
davit petraasya
davit petraasya on 25 Jan 2016
Edited: Stephen23 on 25 Jan 2016
Hi Walter! My x and y values known (attached files).x values different for the parts overlap. So my result graph should include all data from 1 and 2 graph. If in second graph has no corresponding point in first graph my result graph should come without changing, it should come all points.(it should not be any missing point).The result graph should start from 3.5 till 50.
Thank you very much for your help!
You can use max() of the two beginning bounds to find the starting point of the overlap, and min() of the two end points to find the end point of the overlap. From each, extract the range that is in common to both. Then take the union() of those two to get all of the sample points together. Use that common set of points as target points for interp1() on each of the two, and add the two results together.
I have been up all night so I think I will skip showing the code. Pretty much like http://www.mathworks.com/matlabcentral/answers/256459-checking-ismember-intersect-for-lot-of-arrays
Great. Thanks Walter!
davit petraasya
davit petraasya on 27 Jan 2016
Edited: davit petraasya on 27 Jan 2016
Hi! It would be great if you someone can help me on this issue. Last time Walter helped me a lot, but still I did not get result. So my problem is I have 2 excel tables (see attached files, you can see my plots on my first message above ).I need to sum my 2 y values data and get one result curve. The size of the 2 y also different. One point is my result graph should start from zero(year). (on new graph -my previous 1-graph(serre pancon) year 1960 point should be equal to 0, and on my previous 2-graph 1959 year should be correcponding to 0 year on new result graph. Binning would be yearly. Thanks a lot!
all_times = unique([first_times(:); second_times(:)]);
first_projected = interp1(first_times, first_data, all_times, 'extrap', nan);
second_projected = interp1(second_times, second_data, all_times, 'extrap', nan);
first_projected(isnan(first_projected)) = 0;
second_projected(isnan(second_projected)) = 0;
data_total = first_projected + second_projected;
plot(all_times, data_total)
You can subtract all_times(1) from all_times if you want the earliest time between the two to correspond to 0.
If you want to align the first data relative to the beginning of 1960 and the second data relative to the beginning of 1959 and you want the relative positions to be considered the same even though the years are different, then before this code,
first_times = first_times - datenum('1960/1/1');
second_times = second_times - datenum('1959/1/1');
Hi Walter. Thank you so much for the code! It helps:)
Thank you once more for the code Walter. It works well. One last thing actually I had 28 table for summing values. For some tables it appears error -The values of X should be distinct. Is there any way to get rid of the problem? Thanks a lot!
Can you please give me soon the full code? I also have same problem and want it urgently. Will be waiting for yours reply. Thank you.
davit petraasya is probably not following this topic any longer, as it is a year old.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!