help with summing array (sigma sigma)

8 ビュー (過去 30 日間)
sam
sam 2013 年 6 月 15 日
Q Write a m-file e74.m that generates a random matrix A that is always 200 in width, and calculates the sum Σ Σ Where A is of width 200 and height H. The file e74.m should use a nested for-loop (two for loops nested in each other).
sorry for the previous incorrect format
this is what i have so far..... Better?
SumOfNumbers=0
SumOfNumbers= SumOfNumbers + A(j,k)^2
[rows,columns] = Size(A)
for j=1:200 % row index
for k=1:n % column index
disp(A(k,j))
end

回答 (1 件)

Image Analyst
Image Analyst 2013 年 6 月 15 日
Huh? You have 3 for loops instead of two (one over rows and one over columns). What is the loop over n for? Plus, you aren't doing any summing at all! Where is the sum line, like theSum = theSum + A(k,j)????
Next, the width is 200 columns ( not the height), so why are you iterating over 200 rows instead of 200 columns?
Please read this to learn how to format your code:
  2 件のコメント
Image Analyst
Image Analyst 2013 年 6 月 15 日
編集済み: Image Analyst 2013 年 6 月 15 日
Regarding your edit: you don't need the first 3 lines. You need another end to finish the first for loop, and you need a summing line like I already told you, plus you need to initialize theSum to zero before the loops. Plus your for loop limits are wrong. Hint:
[rows, columns] = size(A)
Use rows and columns in the for loop.
Image Analyst
Image Analyst 2013 年 6 月 15 日
Getting better, but you still didn't read my comment above because you haven't implemented most of the fixes I told you. Please read it again and do some of the things - all of them actually.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by