Specifying the iteration range for 'for' loops
古いコメントを表示
Say I have a matrix of size 5-by-5. I want to sum the elements in the rows, but I don't want to sum from the first column all the time, I want to choose from which column to sum from for any row. So say first row I want to sum 2:5, 2nd row 1:5, 3rd row 4:5, etc. How do I do this?
採用された回答
その他の回答 (1 件)
Cris LaPierre
2019 年 2 月 1 日
0 投票
Are those arbiltrary choices of the columns to sum or is there a pattern?
If doing this with a for loop, ideally you are looping through each row, but the exact same code is executed for each row. You'd have to code the pattern into the code that executes. If you can't be more precise on how the columns are selected, I'm afraid you'd either have to preprocess your data by zeroing the data you don't want to sum, or you'd have to manually sum each row.
1 件のコメント
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!