Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matlab for loop

Status
Not open for further replies.

mechMH

Mechanical
Joined
Apr 17, 2018
Messages
4
Location
EG
Hi everyone,
i'm working on a code which has two 5*3 matrices,I want to add each column in say matrix "A" to every column in matrix "B"
so the resultant matrix is 5*9.
I'm doing it with FOR loop but it only returns the final column values. I hope if there are any suggestions!
 
If you are doing loops, bear in mind two things:

1) Pre-allocate your array (Greg's first line). Never grow it.
2) Realise that the neat and satisfying one-liners (vectorized solutions) don't have as much advantage over loops these days.


Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top