Matlab cannot read string data

Hi everyone,
please help me,
i have a xls file with 6 column. First column is string type and others are numeric. i don't know why i cant read the first column data with 'xlsread'. maybe because it is string. is there any way to read my first column?
Thankyou

1 Kommentar

Star Strider
Star Strider am 28 Apr. 2020
The xlsread funciton has three possible outputs. The first is numeric data, the second is character data, and the third is a cell array of everything in the file. Return all the outputs, then experiment with how best to extract the non-numeric data you want.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam Danz
Adam Danz am 28 Apr. 2020

0 Stimmen

Straight out of the documentation
num = xlsread(filename) reads the first worksheet in the Microsoft® Excel® spreadsheet workbook named filename and returns the numeric data in a matrix.
Try using readtable or readcell.

7 Kommentare

hello Adam Danz, please help me again
here is my code
function loadbutton_Callback(hObject, eventdata, handles)
% hObject handle to loadbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,path] = uigetfile('.xlsx')
dataExcel = xlsread(fullfile(path,filename),'sheet1','A2:F50')
global skor;
global ipk;
global gjbb;
global nama;
cla
axes(handles.axes1)
ipk = dataExcel(:,6)
plot(ipk,'-b.')
grid on
legend('Data Mahasiswa')
ylabel('IPK')
set(gca,'xtick',0:5:size(ipk))
set(gca,'XtickLabel',0:5:size(ipk))
set(gca, 'FontSize', 8)
axes(handles.axes2)
skor = dataExcel(:,5)
plot(skor,'-b.')
grid on
legend('Data Mahasiswa')
ylabel('Skor')
set(gca,'xtick',0:5:size(skor))
set(gca,'XtickLabel',0:5:size(skor))
set(gca, 'FontSize', 8)
axes(handles.axes3)
gjbb = dataExcel(:,4)
plot(gjbb,'-b.')
grid on
legend('Data Mahasiswa')
ylabel('Gaji Beban(Juta)')
set(gca,'xtick',0:5:size(gjbb))
set(gca,'XtickLabel',0:5:size(gjbb))
set(gca, 'FontSize', 8)
nama = dataExcel(:,2)
function processbutton_Callback(hObject, eventdata, handles)
fis=readfis('fuzzy.fis');
global ipk
global skor
global gjbb
global nama
out = evalfis([ipk, skor, gjbb],fis)
tableData = [nama,ipk, skor,gjbb,out];
tableData = flipud(sortrows(tableData,5));
set(handles.uitable1,'data',tableData(1:10,:),'ColumnName',{'Nama';'IPK';'Skor_Perilaku';'Gaji_Beban';'Output'});
and here is the result
I dont know why the first column is 'NaN'
what should i do to fix it?
Thankyou
I dont know why the first column is 'NaN'
I explained why in my answer. This line below is only reading in numeric data.
dataExcel = xlsread(fullfile(path,filename),'sheet1','A2:F50')
joni nababan
joni nababan am 28 Apr. 2020
Thankyou Adam
So, how i fix it so that the data can be read?
Adam Danz
Adam Danz am 28 Apr. 2020
As I mentioned in my answer, try using readtable. There's a link to that function in the answer.
Star Strider also mentioned the additional outputs to xlsread that could solve the problem.
If you get stuck, share the updated section of code that reads in the data.
joni nababan
joni nababan am 29 Apr. 2020
i have use readtable but it's error
this is the error
Error using readtable (line 129)
Invalid parameter name: sheet1.
dataExcel = readtable(fullfile(path,filename), 'sheetname', 'sheet1', 'range', 'A2:F50', 'readvariablenames', false);
joni nababan
joni nababan am 29 Apr. 2020
Hi, Walter
Thankyou somuch

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 28 Apr. 2020

Kommentiert:

am 29 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by