필터 지우기
필터 지우기

To subtract the output of a for loop manipulation sequentially from a data set

조회 수: 2 (최근 30일)
segun
segun 2015년 11월 29일
편집: Thorsten 2015년 11월 30일
Please i need hint on how to make the output of this for loop (N) to be subtract from M sequentially without skipping any of the numbers. I tried this code and it did not give me the correct answer as it ignored some numbers.
for f = [1 4 8 10 14 18 22 26 30 34 38 42 45 48 52];
b=2;
c=1;
d=1;
N= f*b*c*d;
end
M=[4.5 10.5 20.5 25.6 30.8 34.6 35.8 38.4 17.2 18.5 20.5 22.6 24.5 26.6 28.9];
Y = (M-N);
A = sum(Y);
disp(A)
[EDITED, Jan, please apply a proper code formatting - Thanks]
  댓글 수: 3
dpb
dpb 2015년 11월 29일
How is this any different from the previous question other than the length of the input vectors? <how-to-get-the-sum-of-the-difference-of-the-output-from-a-multiplication-and-a-data-set>?
As before, you've again got constants inside a looping structure which is of no use and I showed the individual results there the first time until you said it wasn't the answer were looking for.
As Jan says, you've got to first define the problem unequivocally if it isn't as give previously.
Thorsten
Thorsten 2015년 11월 30일
편집: Thorsten 2015년 11월 30일
Could you provide a small example that shows the input and the expected result?

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

답변 (1개)

Jan
Jan 2015년 11월 29일
A bold guess:
f = [1 4 8 10 14 18 22 26 30 34 38 42 45 48 52];
b = 2;
c = 1;
d = 1;
N = f*b*c*d;
M = [4.5, 10.5, 20.5, 25.6, 30.8, 34.6, 35.8, 38.4, 17.2, 18.5, 20.5, 22.6, ...
24.5, 26.6, 28.9];
Y = (M-N);
A = sum(Y);
disp(A)
  댓글 수: 5
segun
segun 2015년 11월 30일
편집: segun 2015년 11월 30일
Please kindly check this code sent to me by somebody who i explained what i wanted to do with this style of coding as i know you are more experienced in MATLAB.
for f= [1 4 8 10 14 18 22 26 30 34 38 42 45 48 52]; b = 2; c = 1; d = 1; N =zeros; N = f*b*c*d; end M = [4.5, 10.5, 20.5, 25.6, 30.8, 34.6, 35.8, 38.4, 17.2, 18.5, 20.5, 22.6 ,24.5, 26.6, 28.9]; N= 0; for k =1:length(M); for i = 1:length(N); Y = sum(M-N) ; end end disp(Y)
dpb
dpb 2015년 11월 30일
It doesn't help to explain non-working code with the same non-working code. We need to see what the answer that you think you should get is and how you arrived at it, not code that doesn't do what you intend it to do. Also, show what the end problem is for which the previous solution didn't work.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by