Thread Subject: how to add total quantity of a row using for loop?

Subject: how to add total quantity of a row using for loop?

From: rohan patel

Date: 4 Nov, 2009 23:56:04

Message: 1 of 4

'Game' 'January' 'February' 'March' 'April' 'May' 'June'
  'iKitty' 75] 254 1235 1820 2114 1600
'ShootEmUp' 3584] 4588 9421 10588 12788 16889

thanks to Tideman,
This code below takes the data from excel and makes them in rows and columns; so if new games want to be added it will create new rows and columns as well.

numbers, text, everything] = xlsread(fileName);

[ngames,nmonths]=size(numbers);
[ for igame=1:ngames
      Game.(text{igame+1,1})=numbers(igame,:);
end

my problem is i have to use for loop to find the sum of each game, for example, total quantity for iKitty is 7098. how can i do this? i need to figure it out so if new games are added to the data it will automatically add their rows as well.

Subject: how to add total quantity of a row using for loop?

From: dpb

Date: 5 Nov, 2009 14:20:00

Message: 2 of 4

rohan patel wrote:
> 'Game' 'January' 'February' 'March' 'April' 'May' 'June'
> 'iKitty' 75] 254 1235 1820 2114 1600
> 'ShootEmUp' 3584] 4588 9421 10588 12788 16889
>
> thanks to Tideman,
> This code below takes the data from excel and makes them in rows and
columns; so if new games want to be added it will create new rows and
columns as well.
>
> numbers, text, everything] = xlsread(fileName);
>
> [ngames,nmonths]=size(numbers);
> [ for igame=1:ngames
> Game.(text{igame+1,1})=numbers(igame,:);
> end
>
> my problem is i have to use for loop to find the sum of each game,
> for example, total quantity for iKitty is 7098. how can i do this? i
> need to figure it out so if new games are added to the data it will
> automatically add their rows as well.

Why do you need to use a for loop?

doc sum % look at optional 'dim' argument

--

Subject: how to add total quantity of a row using for loop?

From: rohan patel

Date: 5 Nov, 2009 16:32:04

Message: 3 of 4

dpb <none@non.net> wrote in message <hcun88$lh0$1@news.eternal-september.org>...
> rohan patel wrote:
> > 'Game' 'January' 'February' 'March' 'April' 'May' 'June'
> > 'iKitty' 75] 254 1235 1820 2114 1600
> > 'ShootEmUp' 3584] 4588 9421 10588 12788 16889
> >
> > thanks to Tideman,
> > This code below takes the data from excel and makes them in rows and
> columns; so if new games want to be added it will create new rows and
> columns as well.
> >
> > numbers, text, everything] = xlsread(fileName);
> >
> > [ngames,nmonths]=size(numbers);
> > [ for igame=1:ngames
> > Game.(text{igame+1,1})=numbers(igame,:);
> > end
> >
> > my problem is i have to use for loop to find the sum of each game,
> > for example, total quantity for iKitty is 7098. how can i do this? i
> > need to figure it out so if new games are added to the data it will
> > automatically add their rows as well.
>
> Why do you need to use a for loop?
>
> doc sum % look at optional 'dim' argument
>
because my teacher said i cant use built in functions

Subject: how to add total quantity of a row using for loop?

From: Steven Lord

Date: 5 Nov, 2009 18:18:40

Message: 4 of 4


"rohan patel" <rpatel133@live.com> wrote in message
news:hcuum4$3ci$1@fred.mathworks.com...
> dpb <none@non.net> wrote in message
> <hcun88$lh0$1@news.eternal-september.org>...
>> rohan patel wrote:

*snip*

>> Why do you need to use a for loop?
>>
>> doc sum % look at optional 'dim' argument
>>
> because my teacher said i cant use built in functions

Then you cannot complete the assignment as specified. XLSREAD is an M-file,
but it uses built-in functions for some of its work. SIZE is also a
built-in function, as is PLUS (which you're using in its operator form to
compute igame+1 inside the FOR loop.) I think it unlikely you're going to
be able to solve this problem just using keywords. I suppose you could
solve it in MEX, but you'd have to ask your teacher if they considered the
mx* functions (which you would need to use) as built-in functions.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com