How do you multiply two arrays with a for loop?

조회 수: 3 (최근 30일)
Graduate Student
Graduate Student 2018년 5월 17일
편집: Graduate Student 2018년 5월 17일
I have two separate arrays, both 1 column. However, Array1 is 300 cells, while Array2 is 600000 cells. I want to iterate through both of these arrays simultaneously. For each element in Array1, I would like to multiply it by 2000 elements in Array2, saving the output.
Then the second element in Array1 would be multiplied by the next 2000 elements in Array2. And so forth.

채택된 답변

the cyclist
the cyclist 2018년 5월 17일
편집: the cyclist 2018년 5월 17일
I think you want something like
out = reshape(Array2,300,[]) .* Array1;
Then you can use reshape again to bring it back to one long vector if you need to.
If that does not do what you intend, perhaps you could provide example input and output for a small "toy" instance, for example where Array1 = 3x1 and Array2 = 6x1.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by