xlsread not reading text only excel file
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to get xlsread to read a excel file that has mostly text. This is my excel file.
test.xlsx
Patrice Oneal 22-Jun-2012 Bill Burr 9-Dec-10
For some reason MATLAB turns the variable with the filename to []. I can't figure out why. I don't think that the code is reading the test.xlsx file.I would like for MATLAB to put the file into an array, however MATLAB just stores the variable that is supposed to contain the array with a "[]". I don't understand why? Can someone explain what I am doing wrong, and how to fix it?
Here is my code:
% Clear all variables screen clear all
% Clear screen clc
% Ask user if they have an excel file they would like to read from prompt = ('Do you have an excel file to add to list? y/n \n'); user_ans_file = input(prompt,'s');
% If/else statement if the user says yes to having an Excel file
if user_ans_file == 'y'
% Ask user if the Excel file is in the write format
prompt = ('Is the excel file in the correct format [First Name|Last Name|dd-mmm-yyyy]? y/n \n');
user_ans_format = input(prompt,'s');
% If/else statement if the user says yes to having an Excel file in the write format
if user_ans_format == 'y'
% Ask user if the Excel file is in the write format
prompt = ('what is the name of the file with the .xlsx extention? \n');
file_name = input(prompt,'s');
% file_name = 'file_name'.xlsx;
% Read the Excel file that the user stated
num = xlsread(file_name);
end
else
end
--Ender--
0 Commenti
Risposta accettata
Iain
il 8 Ago 2014
You're only reading out the numbers, you want to read the file with:
[numbers, TEXT, everything] = xlsread(file_name);
TEXT{2,1} is cell A2.
3 Commenti
Ntwanano Baloyi
il 21 Mag 2022
This was very helpful. How do I read the data from other sheets because I used this and it read data from sheet 1 only
Più risposte (2)
Andy L
il 7 Ago 2014
Modificato: Andy L
il 8 Ago 2014
First of all your filename. You use the following lines of code to set up your file name:
file_name = input(prompt,'s');
Are you adding the .xlsx extension to the file name? This may be having an effect. You can add the extension by the following code:
file_name = [file_name,'.xlsx'];
As for the empty data array have you checked the matlab help for xlsread? num returns the numeric only data from the file. If you use the following format of the function
[num,txt,raw] = xlsread()
This should return the text data in a cell array txt. There is more information on the function in that link.
1 Commento
madhan ravi
il 19 Mar 2018
Modificato: madhan ravi
il 19 Mar 2018
[num,txt,raw] = xlsread()-> only numbers are displayed even though the file contains text
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!