- When incrementing by one, you can simply do i=0:2, the increment value is only necessary if it is something other than 1
- You can simplify your code to do all the calculations on one line
- It is simpler to just add to S every loop iteration.
Folks, please let me know how to complete the sum of products in the "for loop" as shown below in order to get the correct answer. Thank you. HDaniel
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hani daniel
am 9 Aug. 2017
Kommentiert: hani daniel
am 10 Aug. 2017
clear all; % S=2i*3j; S1=0; S2=0; for i=0:1:2; for j=1:1:3; S1=2*i; S2=3*j; S=S1*S2; end end y=Sum(S)
0 Kommentare
Akzeptierte Antwort
aborghes
am 9 Aug. 2017
Bearbeitet: aborghes
am 9 Aug. 2017
Hi Hani,
A few tips first:
Doing as i suggest, the code looks as follows:
clear all;
% S=2i*3j;
S = 0;
for i=0:2
for j=1:3
S= S + 2*i * 3*j;
end
end
y=S
2 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!