フィルターのクリア

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 Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by