Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: how to find unique rows and calculate the average.
Replies: 9   Last Post: Apr 12, 2013 6:31 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,231
Registered: 6/7/07
Re: how to find unique rows and calculate the average.
Posted: Apr 11, 2013 7:51 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/11/2013 5:50 PM, Alan Hitch wrote:

...[top-posting repaired--don't do that; hard conversation follow makes]...

> dpb <none@non.net> wrote in message <kk58cv$2k3$1@speranza.aioe.org>...
>> On 4/10/2013 4:10 PM, Alan Hitch wrote:
>> ...
>>

>> > Thanks for responding. I neglected to tell you that the data is a cell
>> > array with different data types and textscan only works with double or
>> > string. I read the data in using xlsread and was using the raw data. I
>> > am relatively new to MatLab. How do I convert the cell array into a
>> > double or string? I tried using cell2mat but the contents of my
>> > cellarray are different data types.

>>
>> OK, it just dawned on me--your problem is trying to use RAW; use TEXT
>> as the C{1} cell in my example and NUM as the C{2}. Since XLSREAD
>> returns the numeric fields as a double array instead of cell, just
>> dispense w/ the curly brackets to dereference the cell contents and
>> just use the subscripting expressions directly into NUM. (Of course,
>> use whatever variable names you wish instead of the ML placeholders...)


...

> I know this will work once I get the textscan line of code to work.
> If I am reading in a xls file with (txt,num,raw) which array should I
> put in the "fid" place? That is confusing me right now. After that is
> done everything should work fine. Thanks again for all your help.


That's what I was saying just realized--if it is an Excel spreadsheet
that you're trying to read, TEXTSCAN() can't do it--it reads, well, 'text'.

I was just pointing out that when you use XLSREAD that text that is the
ID column, etc., is in the TXT cell array while the numeric values are
in NUM. The TEXTSCAN line goes away; fid is the file handle obtained
from fopen() on the file but xlsread takes the filename and opens it
internally instead.

I have to admit I've never used XLSREAD so I'm not absolutely positive
how it structures the cell array(s) it returns--one thing that is clear
is that you'll have to either start the location where it reads the file
from the cell below the header line whichever line that is on inside the
sheet or it will also be mixed up in the TXT array and I've no clue what
it'll do about the NUM array to match.

Alternatively, if TXT is a cell array of rows, it should be reasonably
easy to use Bruno's solution on it--I have only recently been blessed w/
a new-enough release of Matlab to incorporate accumarray and various
other new-fangled things despite 20 yrs w/ Matlab. Consequently I tend
to forget about them.

In summary, the TEXTSCAN solution works only if you save the file to a
text file and read it; you'll have to look at how XLSREAD returns the
data to figure out how to do the equivalent addressing that is shown in
both Bruno's and my approaches to find the correct rows and associated data.

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.