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일
1 개 추천
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!
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
