xlsread for many distinct columns that aren't side-by-side in the SS
이전 댓글 표시
Hi,
I know this is probably simple, but I'm not finding what I need when searching here.
I want to use xlsread to import many distinct columns that are not side-by-side in the spreadsheet. How can I do that? What am I missing? :)
My normal use of xlsread would be like this if I need columns A-D:
[File,Path] = uigetfile(blah, blah, blah);
File = strcat(Path,File);
DataVariable = xlsread(File,1,A:A:D:D);
How would I change this if I wanted, say, columns A and columns D-F? I've tried many different things, but have suffered death by commas, semicolons, and error messages.
Any help is appreciated.
댓글 수: 2
John
2014년 2월 26일
Please, John, do not bump your question after a few hours without addibng new information. The voluntary helpers post answers whene ever they have them and find the time to help. Reading a question again is a waste of time then.
The posted code is not working. Did you forget the quotes around A:A:D:D? But even then this is not correct.
답변 (4개)
Jan
2014년 2월 26일
Import the block at first:
[File,Path] = uigetfile(blah, blah, blah);
File = fullfile(Path,File); % Smarter than STRCAT
DataVariable = xlsread(File,1,'A1:F231');
Now remove the not needed data from the output DataVariable.
This is not nice, but it works reliably.
댓글 수: 2
John
2014년 2월 27일
Image Analyst
2014년 2월 27일
Does your xlsread call specify a range? You might have to process your data in smaller chunks.
Image Analyst
2014년 2월 26일
0 개 추천
Have you tried readtable() - it's new in R2013b and reads the Excel workbook into a table which is a lot more convenient than that mess of cell arrays xlsread() spits out. I've kissed xlsread() goodbye. You will too after you use readtable().
댓글 수: 4
Image Analyst
2014년 2월 26일
Here's an example:
% Read in Book1 which has numbers in column A
% nothing at all in column B, and letters in column C.
t = readtable('book1.xlsx');
% I had column B be empty so it's all nans.
% Delete that column
t(:,2)=[];
% Now t has 2 columns like we want (columns A and C from Excel);
Image Analyst
2014년 2월 26일
편집: Image Analyst
2014년 2월 26일
You can also use xlsread if you have to
[numbers, strings, raw] = xlsread(filename);
colA = raw(:,1);
colDF = raw(:,4:6);
The only reason you'd do it this way instead of readtable is if you need to run this on an old version of MATLAB (before R2013b).
John
2014년 2월 27일
John
2014년 2월 27일
Sean de Wolski
2014년 2월 27일
0 개 추천
Use an automation server to read in only the chunks you need:
댓글 수: 3
John
2014년 2월 27일
Sean de Wolski
2014년 2월 27일
If you contact our customer service department they can straighten that out.
Otherwise just search for "Excel Automation" in the MATLAB doc; it should be the first result.
John
2014년 2월 27일
Nick Haddad
2014년 10월 3일
0 개 추천
This issue is a known bug in MATLAB and has been addressed in the following bug report:
The bug report has a workaround which you can install for MATLAB R2013a through R2014b.
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!