Trouble with variable names when importing from excel

8 views (last 30 days)
Hi,
I am trying to import a large excel workbook. The problem is that although i have the right row for the variable names, matlab does not pick it up and either puts a Varname? or a name that does not correspond to the one in the designated row...
  2 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 28 Oct 2013
Edited: Azzi Abdelmalek on 28 Oct 2013
Some information are missing, can you be more clear? for example post a sample of your data, the lines of your code that import your Excell file, and explain what is your problem
Meli
Meli on 29 Oct 2013
Thank you for your response! I am using Excel 2003 Matlab R2013b's import data utility, so no code is involved.
I am posting the workbook with some of the data as well as a screen capture of the imported data.
Thank you very much for your time!
Meli.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 29 Oct 2013
Yes, if you have both numbers and text in the Excel cells, they are out of sync. In other words, say you have row 1 as column headers, and data below it. And say you say
[num, txt, raw] = xlsread(filename);
Then row 1 of txt will contain your column headers (no problem there - it's what you expect). But the numbers will not be in row 2 of num (the same row number they were in when they were in Excel). The numbers from row 2 in Excel will be in row 1 of num - not what one would expect unless you've encountered this before. So you need to adjust the row number that you are using to reference your Excel cells after they've been pulled into MATLAB. Or you can just deal with the raw where the numbers and strings don't get out of sync (though I haven't tested it to see what row things are in in raw if they start at, say, row 30 in Excel).
  3 Comments
Image Analyst
Image Analyst on 29 Oct 2013
Edited: Image Analyst on 29 Oct 2013
I didn't know that about the syncing discrepancies between versions. It's something to keep an eye on. I, too, though use the raw return cell array almost every time where I'm dealing with mixed string/number data because that syncing issue drives me nuts and I just want to avoid it.
Actually Cedric, you have a phenomenal acceptance rate. Way higher than mine. And I don't know how Greg Heath does it - his is very high - possibly because he's the about only one here who knows neural networks. Although I lose about half my answers due to the poster accepting the wrong one or trying to accept multiple answers, not knowing that you can only accept one. I've been on the losing end of a lot of them this month, for example http://www.mathworks.com/matlabcentral/answers/91055#comment_175860 where I even warned the poster in advance that the other answer was wrong and they still accepted it despite my warning. A lot of well meaning beginners suggest working but inefficient non-vectorized methods and they'll often take those because they don't like my vectorized answer or don't understand it. But I've been impressed by your knowledge - you're not one of the well meaning but unskilled/inexperienced programmers at all.
Cedric
Cedric on 29 Oct 2013
Edited: Cedric on 29 Oct 2013
Thank you for your comment, Image Analyst, I really appreciate.
The discrepancies between versions have been driving me nuts and some of my models have to test MATLAB version for being able to import Excel files adequately. I am not complaining too much though, because I think that backward compatibility is quite good with MATLAB. I also have to say that I wouldn't be against a major break in this backward compatibility for a complete language update, but that's another story.
I know what you mean by posters not accepting the best answer (in terms of efficiency and elegance). It happens to me occasionally and I think that people are sometimes reassured by simple FOR loops which correspond to their initial idea.. or sometimes they might want the largest amount of code because it looks impressive(?) In any case, I sympathize with you on that matter.
For the acceptance rate, well, we'll talk again when I'll hit a rep of 10,000, because it seems that most high rep. people are converging towards this ratio of 1/4 to 1/3 of answers being accepted. If it's easy to keep a good ratio with my rep. close to 1,000, I'd bet that I'll converge like all of you towards this 1/4 to 1/3 ratio finally! I already wrote about it, saying that it seems that over the 2/3 not accepted, 1/3 is due to the acceptance of another solution, and 1/3 is due to people never coming back or just not clicking on [ Accept ]. When I'll have more time (to fight against this last 1/3), I am likely to build a web crawler for spotting threads which
  • have only one answer,
  • not accepted,
  • have a comment from the author of the question which contains some form of "thank you".
I think that answers in such threads can legitimately be accepted, or at least I would have no problem in accepting them.
As you mention Greg Heath's high ratio, he is now at 450/722, which is roughly 2/3. He is therefore the live demonstration of what I said above, as he is almost the only person answering questions involving neural networks, and is therefore just experiencing the people who don't click on accept or who never come back, which leads to the remaining 1/3.
On that note, I am off for the evening. Have a good night!

Sign in to comment.

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!