Thread Subject: how to make rows and columns from excel files? please help

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 01:14:03

Message: 1 of 13

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

okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.

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

iKitty = numbers(1,:);
shootEmUp = numbers(2,:);

but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?

Subject: how to make rows and columns from excel files? please help

From: TideMan

Date: 4 Nov, 2009 02:19:23

Message: 2 of 13

On Nov 4, 2:14 pm, "rohan patel" <rpatel...@live.com> wrote:
> 'Game'         'January'    'February'    'March'    'April'    'May'      'June'
>  'iKitty'            75]         254           1235     1820      2114     1600
> 'ShootEmUp'   3584]     4588          9421     10588    12788    16889
>
> okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
>
> [numbers, text, everything] = xlsread(fileName);
>
> iKitty = numbers(1,:);
> shootEmUp = numbers(2,:);
>
> but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?

One solution is to use a structure:
[ngames,nmonths]=size(numbers);
for igame=1:ngames
   Game.(text{igame+1,1})=numbers(igame,:);
end

Subject: how to make rows and columns from excel files? please help

From: ade77

Date: 4 Nov, 2009 02:33:01

Message: 3 of 13

do you insist that the name of the variable must be the name of the game. That is the variables must be named iKitty, ShootEmUp etc, that will mean trying to convert a string or char into the name of a variable.
That is the only issue with this problem, which I am not sure how to do. Otherwise, there are many ways , like what the last poster did.

If the user can name the games whatever variable, then it will be much easier. Of course there must be a way around it, I am not just sure how to go about it.

"rohan patel" <rpatel133@live.com> wrote in message <hcqkgq$n9$1@fred.mathworks.com>...
> 'Game' 'January' 'February' 'March' 'April' 'May' 'June'
> 'iKitty' 75] 254 1235 1820 2114 1600
> 'ShootEmUp' 3584] 4588 9421 10588 12788 16889
>
> okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
>
> [numbers, text, everything] = xlsread(fileName);
>
> iKitty = numbers(1,:);
> shootEmUp = numbers(2,:);
>
> but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 04:27:01

Message: 4 of 13

TideMan <mulgor@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d1fe@m3g2000pri.googlegroups.com>...
> On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
> >
> > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
> >
> > [numbers, text, everything] = xlsread(fileName);
> >
> > iKitty = numbers(1,:);
> > shootEmUp = numbers(2,:);
> >
> > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
>
> One solution is to use a structure:
> [ngames,nmonths]=size(numbers);
> for igame=1:ngames
> Game.(text{igame+1,1})=numbers(igame,:);
> end

okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
and
i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?

Subject: how to make rows and columns from excel files? please help

From: ade77

Date: 4 Nov, 2009 04:45:20

Message: 5 of 13

Actually, the code below will do the job for you, not only will it find all the rows, it will also give the actual name of the string like ikitty, ShootEmUp etc

[numbers, text] = xlsread('your excel file');
u = size(text);
 for i = 2:u
V = genvarname(text{i,1});
eval([V '= numbers(i-1,:);']);
 end
clear V u i numbers text % you can remove this last line if you like.

The last line of code is just to free memory. The only thing you will have left is your game variables and the associated arrays.

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 05:29:03

Message: 6 of 13

"ade77 " <ade100a@gmail.com> wrote in message <hcr0t0$8r2$1@fred.mathworks.com>...
> Actually, the code below will do the job for you, not only will it find all the rows, it will also give the actual name of the string like ikitty, ShootEmUp etc
>
> [numbers, text] = xlsread('your excel file');
> u = size(text);
> for i = 2:u
> V = genvarname(text{i,1});
> eval([V '= numbers(i-1,:);']);
> end
> clear V u i numbers text % you can remove this last line if you like.
>
> The last line of code is just to free memory. The only thing you will have left is your game variables and the associated arrays.

okay, thanks, but now i have another problem i want to find the total number of quantity sold in for each game so how would i "for loop" it to add to get results for each game?

Subject: how to make rows and columns from excel files? please help

From: TideMan

Date: 4 Nov, 2009 07:16:59

Message: 7 of 13

On Nov 4, 5:27 pm, "rohan patel" <rpatel...@live.com> wrote:
> TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
>
> > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
>
> > > [numbers, text, everything] = xlsread(fileName);
>
> > > iKitty = numbers(1,:);
> > > shootEmUp = numbers(2,:);
>
> > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
>
> > One solution is to use a structure:
> > [ngames,nmonths]=size(numbers);
> > for igame=1:ngames
> >    Game.(text{igame+1,1})=numbers(igame,:);
> > end
>
> okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> and
> i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?

Yes, my method will expand as you add extra rows.
Please do not listen to posters who suggest that you use the eval
function.
It is an evil function that will lead to you to unhappiness.

Subject: how to make rows and columns from excel files? please help

From: TideMan

Date: 4 Nov, 2009 07:20:09

Message: 8 of 13

On Nov 4, 5:45 pm, "ade77 " <ade1...@gmail.com> wrote:
> Actually, the code below will do the job for you, not only  will it find all the rows, it will also give the actual name of the string like ikitty, ShootEmUp etc
>
> [numbers, text] = xlsread('your excel file');
> u = size(text);
>  for i = 2:u    
> V = genvarname(text{i,1});
> eval([V '= numbers(i-1,:);']);
>  end
> clear V u i  numbers text      % you can remove this last line if you like.
>
> The last line of code is just to free memory. The only thing you will have left is your game variables and the associated arrays.

Please do not top post. It makes the thread hard to follow. Put your
reply UNDERNEATH.

You are out of order suggesting eval to a newbie.
It is exactly the wrong way to do things.

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 19:32:03

Message: 9 of 13

TideMan <mulgor@gmail.com> wrote in message <36c3a68d-10d9-4573-bf0c-6a60ef50eaa6@g23g2000yqh.googlegroups.com>...
> On Nov 4, 5:27?pm, "rohan patel" <rpatel...@live.com> wrote:
> > TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
> >
> > > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
> >
> > > > [numbers, text, everything] = xlsread(fileName);
> >
> > > > iKitty = numbers(1,:);
> > > > shootEmUp = numbers(2,:);
> >
> > > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
> >
> > > One solution is to use a structure:
> > > [ngames,nmonths]=size(numbers);
> > > for igame=1:ngames
> > > ? ?Game.(text{igame+1,1})=numbers(igame,:);
> > > end
> >
> > okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> > and
> > i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?
>
> Yes, my method will expand as you add extra rows.
> Please do not listen to posters who suggest that you use the eval
> function.
> It is an evil function that will lead to you to unhappiness.


Tideman, okay i got this. but now my problem is i need to add the rows to get the total quantity for that game. how can i do this without using the sum fuction.

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 19:58:02

Message: 10 of 13

TideMan <mulgor@gmail.com> wrote in message <36c3a68d-10d9-4573-bf0c-6a60ef50eaa6@g23g2000yqh.googlegroups.com>...
> On Nov 4, 5:27?pm, "rohan patel" <rpatel...@live.com> wrote:
> > TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
> >
> > > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
> >
> > > > [numbers, text, everything] = xlsread(fileName);
> >
> > > > iKitty = numbers(1,:);
> > > > shootEmUp = numbers(2,:);
> >
> > > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
> >
> > > One solution is to use a structure:
> > > [ngames,nmonths]=size(numbers);
> > > for igame=1:ngames
> > > ? ?Game.(text{igame+1,1})=numbers(igame,:);
> > > end
> >
> > okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> > and
> > i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?
>
> Yes, my method will expand as you add extra rows.
> Please do not listen to posters who suggest that you use the eval
> function.
> It is an evil function that will lead to you to unhappiness.


Tideman, okay i got this. but now my problem is i need to add the rows to get the total quantity for that game. how can i do this without using the sum fuction.

Subject: how to make rows and columns from excel files? please help

From: TideMan

Date: 4 Nov, 2009 20:02:12

Message: 11 of 13

On Nov 5, 8:58 am, "rohan patel" <rpatel...@live.com> wrote:
> TideMan <mul...@gmail.com> wrote in message <36c3a68d-10d9-4573-bf0c-6a60ef50e...@g23g2000yqh.googlegroups.com>...
> > On Nov 4, 5:27?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > > > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
>
> > > > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
>
> > > > > [numbers, text, everything] = xlsread(fileName);
>
> > > > > iKitty = numbers(1,:);
> > > > > shootEmUp = numbers(2,:);
>
> > > > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
>
> > > > One solution is to use a structure:
> > > > [ngames,nmonths]=size(numbers);
> > > > for igame=1:ngames
> > > > ? ?Game.(text{igame+1,1})=numbers(igame,:);
> > > > end
>
> > > okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> > > and
> > > i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?
>
> > Yes, my method will expand as you add extra rows.
> > Please do not listen to posters who suggest that you use the eval
> > function.
> > It is an evil function that will lead to you to unhappiness.
>
> Tideman, okay i got this. but now my problem is i need to add the rows to get the total quantity for that game. how can i do this without using the sum fuction.

Why would you want to do this without using the sum function?
Is this homework?

Subject: how to make rows and columns from excel files? please help

From: rohan patel

Date: 4 Nov, 2009 22:11:02

Message: 12 of 13

TideMan <mulgor@gmail.com> wrote in message <c5f5c5f5-082a-445e-8cb0-ea3cfdfe314e@g1g2000pra.googlegroups.com>...
> On Nov 5, 8:58?am, "rohan patel" <rpatel...@live.com> wrote:
> > TideMan <mul...@gmail.com> wrote in message <36c3a68d-10d9-4573-bf0c-6a60ef50e...@g23g2000yqh.googlegroups.com>...
> > > On Nov 4, 5:27?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > > > > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > > > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > > > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
> >
> > > > > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
> >
> > > > > > [numbers, text, everything] = xlsread(fileName);
> >
> > > > > > iKitty = numbers(1,:);
> > > > > > shootEmUp = numbers(2,:);
> >
> > > > > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
> >
> > > > > One solution is to use a structure:
> > > > > [ngames,nmonths]=size(numbers);
> > > > > for igame=1:ngames
> > > > > ? ?Game.(text{igame+1,1})=numbers(igame,:);
> > > > > end
> >
> > > > okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> > > > and
> > > > i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?
> >
> > > Yes, my method will expand as you add extra rows.
> > > Please do not listen to posters who suggest that you use the eval
> > > function.
> > > It is an evil function that will lead to you to unhappiness.
> >
> > Tideman, okay i got this. but now my problem is i need to add the rows to get the total quantity for that game. how can i do this without using the sum fuction.
>
> Why would you want to do this without using the sum function?
> Is this homework?

Yes, my teacher is being mean =[ and im stressing out so much. please help me

Subject: how to make rows and columns from excel files? please help

From: TideMan

Date: 4 Nov, 2009 22:40:45

Message: 13 of 13

On Nov 5, 11:11 am, "rohan patel" <rpatel...@live.com> wrote:
> TideMan <mul...@gmail.com> wrote in message <c5f5c5f5-082a-445e-8cb0-ea3cfdfe3...@g1g2000pra.googlegroups.com>...
> > On Nov 5, 8:58?am, "rohan patel" <rpatel...@live.com> wrote:
> > > TideMan <mul...@gmail.com> wrote in message <36c3a68d-10d9-4573-bf0c-6a60ef50e...@g23g2000yqh.googlegroups.com>...
> > > > On Nov 4, 5:27?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > > TideMan <mul...@gmail.com> wrote in message <09f4f3a9-b4b9-47ea-b907-c00fb7e9d...@m3g2000pri.googlegroups.com>...
> > > > > > On Nov 4, 2:14?pm, "rohan patel" <rpatel...@live.com> wrote:
> > > > > > > 'Game' ? ? ? ? 'January' ? ?'February' ? ?'March' ? ?'April' ? ?'May' ? ? ?'June'
> > > > > > > ?'iKitty' ? ? ? ? ? ?75] ? ? ? ? 254 ? ? ? ? ? 1235 ? ? 1820 ? ? ?2114 ? ? 1600
> > > > > > > 'ShootEmUp' ? 3584] ? ? 4588 ? ? ? ? ?9421 ? ? 10588 ? ?12788 ? ?16889
>
> > > > > > > okay i have this. i know how to put in rows and columns for iKitty and ShootemUP.
>
> > > > > > > [numbers, text, everything] = xlsread(fileName);
>
> > > > > > > iKitty = numbers(1,:);
> > > > > > > shootEmUp = numbers(2,:);
>
> > > > > > > but i need to figure out how if there was more data add(such as new game) how can i use a for loop to put everything in row and columns?
>
> > > > > > One solution is to use a structure:
> > > > > > [ngames,nmonths]=size(numbers);
> > > > > > for igame=1:ngames
> > > > > > ? ?Game.(text{igame+1,1})=numbers(igame,:);
> > > > > > end
>
> > > > > okay i done this but if i add another game application to the data sheet will it create rows and columns for that also?
> > > > > and
> > > > > i have another problem i want to find the total number of quantity sold in for each game so how would i for loop it to add to get results?
>
> > > > Yes, my method will expand as you add extra rows.
> > > > Please do not listen to posters who suggest that you use the eval
> > > > function.
> > > > It is an evil function that will lead to you to unhappiness.
>
> > > Tideman, okay i got this. but now my problem is i need to add the rows to get the total quantity for that game. how can i do this without using the sum fuction.
>
> > Why would you want to do this without using the sum function?
> > Is this homework?
>
> Yes, my teacher is being mean =[ and im stressing out so much. please help me

I've helped you enough already.
You can work out how to add up numbers yourself.
One way that doesn't use sum is:
mean(numbers(igame,:)))*length(numbers(igame,:));
but your teacher may think you're being a smartass.

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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com