MATLAB Answers

how can I read spreadsheet file which is not generated by excel in Matlab

5 views (last 30 days)
JINGJING ZANG on 30 Aug 2021
Commented: JINGJING ZANG on 1 Sep 2021
I have spreadsheets with file extension of ´'xls' which were generated by LABVIEW (not EXCEL). Those files can be read in EXCEL.
I tried to use "readtable" "readmatrix" "readcell" or "xlsread" to read those files in matlab. none of them work.
"Unable to open file as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file."
The problem can be solved by using EXCEL to open and save the file as .xls or xlsx file (exactly as the original file name) .
But I am worndering if there is an easy solution in MATLAB.
Thank you very much.

Sign in to comment.

Accepted Answer

dpb on 31 Aug 2021
I thought something like this might be the case -- it's a text, delimited file named as ".xls" -- Excel does have internal smarts to deal with that case, the MATLAB utilities utilize the file extension to decide how to try to open the file so the mismatch of content to file naming convention causes the failure.
>> t=readtable('5hz.xls','FileType','text');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
>> head(t)
ans =
8×4 table
Time_ms_ Trial1_mV_ Average_mV_ Flash1
________ __________ ___________ ______
0 0.113 0.113 1
1 0.116 0.116 1
2 0.113 0.113 1
3 0.113 0.113 1
4 0.1 0.1 1
5 0.103 0.103 1
6 0.1 0.1 1
7 0.074 0.074 1
works as would
which gives a double array instead of table.
Or, you could rename the file to have a .txt or .dat extension.
You might want to check how you're saving these in LABVIEW; I'll bet there's a way to get the file type and name to match up.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!