필터 지우기
필터 지우기

Adding multiple interp1 in a loop

조회 수: 1 (최근 30일)
ugur uresin
ugur uresin 2018년 7월 3일
댓글: ugur uresin 2018년 7월 5일
Creating a loop for adding n number of interp1 functions:
sqrt(interp1(x1,y1,X) + interp1(x2,y2,X) +...+ interp1(xn,yn,X))
Where,
x: is the independent variable
y: is the dependent variable
X: is the range
The PROBLEM is that n is an variable, not a constant.
So, I need to do this in a LOOP.
  댓글 수: 3
ugur uresin
ugur uresin 2018년 7월 5일
They're all double
For example:
x1 =
1.0e+04 *
0.0960
0.0984
0.1008
0.1032
.
.
.
Stephen23
Stephen23 2018년 7월 5일
ugur uresin's "Answer" moved here:
My code is below. This is a manual procedure. I would like to AUTOMATIZE and GENERALIZE this procedure due to the fact that number of variables is not constant -changes by data- (e.g. 8 here).
x1 = rpmmat(:, 1);
x2 = rpmmat(:, 2);
x3 = rpmmat(:, 3);
x4 = rpmmat(:, 4);
x5 = rpmmat(:, 5);
x6 = rpmmat(:, 6);
x7 = rpmmat(:, 7);
x8 = rpmmat(:, 8);
y1 = plotdata_ed2(:, 1);
y2 = plotdata_ed2(:, 2);
y3 = plotdata_ed2(:, 3);
y4 = plotdata_ed2(:, 4);
y5 = plotdata_ed2(:, 5);
y6 = plotdata_ed2(:, 6);
y7 = plotdata_ed2(:, 7);
y8 = plotdata_ed2(:, 8);
rss1 = sqrt(interp1(x1,y1,X)+interp1(x2,y2,X)+interp1(x3,y3,X)+interp1(x4,y4,X)+interp1(x5,y5,X)+interp1(x6,y6,X)+interp1(x7,y7,X)+interp1(x8,y8,X));
I tried many type of loop algorithms but they couldn't run.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 7월 5일
편집: Stephen23 2018년 7월 5일
This is easy one you avoid the counter-productive anti-pattern of creating numbered variables:
yn = 0;
for k = 1:8
xo = rpmmat(:,k);
yo = plotdata_ed2(:,k);
yn = yn + interp1(xo,yo,X);
end
rss = sqrt(yn);
  댓글 수: 1
ugur uresin
ugur uresin 2018년 7월 5일
It works! Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by