필터 지우기
필터 지우기

User Input with Loops

조회 수: 2 (최근 30일)
mike
mike 2014년 12월 6일
댓글: Image Analyst 2014년 12월 7일
Hey guys,
I am wondering is there is a function that can read .xlsx, .csv, and .xls files. I wanted something that could work with the uigetfile('*.*') command For example, I want my user to select a spreadsheet either in .xlsx, .csv, or .xls format and send it through an analysis regardless of what they pick. Currently I have csvread, and was wondering if I could form an loop asking them what format the file is in and send it through it's respective analysis, whether it be xlsxread, xlsread, etc.
I apologize if the questions isn't clear.
Thanks!

채택된 답변

Star Strider
Star Strider 2014년 12월 6일
As far as I know, xlsread can potentially read all of them, provided they’re in Excel format. (The xlsread funciton calls Excel.) If you want to specifically select xlsread or csvread on the basis of the file extension, something like this would work:
filext = {'xls' 'xlsx' 'csv'};
fnm = inputdlg('Enter the full name (+ext) of your file: ');
ext = regexpi(fnm, '[.]?','split');
filtyp = find(strcmpi(ext{:}(2),filext));
followed by a switch-case block to call the appropriate function based on the output in ‘filtyp’, and passing to it the full ‘fnm’ file name.
  댓글 수: 7
Star Strider
Star Strider 2014년 12월 7일
You would have to save them as .csv files, either after having first read them in through MATLAB using xlsread, or directly saving them as .csv files in Excel.
See the documentation for csvwrite for details on writing .csv files in MATLAB.
Thanks!
Image Analyst
Image Analyst 2014년 12월 7일

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 12월 7일
Depending on the way the data is laid out, you could use readtable(). importdata() should also be able to do it since it detects what's there and uses the appropriate lower level importing function (like csvread or xlsread).

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by