How to sum two y axis data
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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!


採用された回答
Walter Roberson
2016 年 1 月 25 日
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 件のコメント
davit petraasya
2016 年 1 月 25 日
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)
Walter Roberson
2016 年 1 月 25 日
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
2016 年 1 月 25 日
編集済み: Stephen23
2016 年 1 月 25 日
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!
Walter Roberson
2016 年 1 月 25 日
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
davit petraasya
2016 年 1 月 25 日
Great. Thanks Walter!
davit petraasya
2016 年 1 月 27 日
編集済み: davit petraasya
2016 年 1 月 27 日
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!
Walter Roberson
2016 年 1 月 27 日
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');
davit petraasya
2016 年 1 月 28 日
Hi Walter. Thank you so much for the code! It helps:)
davit petraasya
2016 年 1 月 31 日
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!
raj das
2017 年 3 月 22 日
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.
Walter Roberson
2017 年 3 月 22 日
davit petraasya is probably not following this topic any longer, as it is a year old.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Animation についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
