From: Georgy on 21 Mar 2010 03:45 Hi all! You can't use any predefined functions, but loops, mathematical operations, if statements, and matrices are allowed. This is my code so far: function Y = addall(X) total = 0; [r c] = size(X); Y = []; for rows = 1:r for cols = 1:c end end I can't seem to find out how to mimic the sum function by adding all the columns together first and then the rows. Anyideas?
From: TideMan on 21 Mar 2010 05:42 On Mar 21, 8:45 pm, "Georgy " <Georg...(a)yahoo.com> wrote: > Hi all! You can't use any predefined functions, but loops, mathematical operations, if statements, and matrices are allowed. This is my code so far: > > function Y = addall(X) > total = 0; > [r c] = size(X); > Y = []; > for rows = 1:r > for cols = 1:c > > end > end > > I can't seem to find out how to mimic the sum function by adding all the columns together first and then the rows. Anyideas? Another homework cheat. Figure it out for yourself.
From: Jan Simon on 21 Mar 2010 15:57 Dear Georgy! > function Y = addall(X) > total = 0; > [r c] = size(X); > Y = []; > for rows = 1:r > for cols = 1:c > > end > end You start with "Y = []". Usually a sum start with 0. Then one element after the other is added. So you just have to find out how to get the elements from the input matrix. Good luck, Jan PS. What does you teacher think about posting the homework in a newsgroup? Teachers are payed for teaching, and you do not ask her or him, but a public newsgroup. Perhaps this get her/him down.
From: Jos (10584) on 21 Mar 2010 16:34 "Georgy " <Georgy46(a)yahoo.com> wrote in message <ho4iq4$5vd$1(a)fred.mathworks.com>... > Hi all! You can't use any predefined functions, but loops, mathematical operations, if statements, and matrices are allowed. This is my code so far: > > function Y = addall(X) > total = 0; > [r c] = size(X); > Y = []; > for rows = 1:r > for cols = 1:c > > end > end > > I can't seem to find out how to mimic the sum function by adding all the columns together first and then the rows. Anyideas? SIZE is a predefined function ...
|
Pages: 1 Prev: Where is urlConnection.setReadTimeout? Next: GPS simulink model |