error message 'char'.how to solve?

function [EPClist,data]=extraction_data(Nomfichier)
dummy=importfile(Nomfichier);
j=1;
for i=1:height(dummy)
if dummy.OperationResult(i)==' Read OK'
data_raw(j,1)=dummy.Date(i);
data_raw(j,2)=dummy.EPC(i);
data_raw(j,3)=dummy.ReadData(i);
j=j+1;
end
end
clear dummy
EPClist=unique(data_raw(:,2));
Nb_capteur=length(EPClist);
data=cell(1,Nb_capteur);
for i=1:Nb_capteur
k=1;
for j=1:length(data_raw)
if data_raw(j,2)==EPClist(i)
%data{i}(k,1)=data_raw(j,1);
%data{i}(k,1)=0;
data{i}(k,1)=hex2dec(data_raw{j,3}(5:8));
temphexa=data_raw{j,3}(9:12);
if temphexa(1)=='F'
data{i}(k,2)=1/100*(hex2dec(temphexa)-hex2dec('FFFF')+1);
else
data{i}(k,2)=1/100*hex2dec(temphexa);
end
k=k+1;
end
end
EPClist{i}=EPClist{i}(end-3:end);
end
Error message:
Undefined function 'importfile' for input arguments of type 'char'.
Error in extraction_data (line 3)
dummy=importfile(Nomfichier);
Error in detect_palier (line 3)
[EPC,B]=extraction_data(titre);
Error in extract_palier (line 23)
[EPC,pression,temperature]=detect_palier(titre,table_delete);

1 个评论

importfile is not a matlab built-in function, could you share its code or where you have taken it from?

请先登录,再进行评论。

回答(1 个)

The function importdata has an option to generate a function that will import other files using the same configuration. It is common for the generated function to be called importfile . But it is not part of MATLAB; it is the result of someone using importdata() and asking to save the associated code.
These days, looking at the imported data, you should probably instead use readtable

6 个评论

Hello,
Sorry i dont understand. and i cant do with read table. because in that case i need change all other part of my program. i can not do this bacause of my work law.
could you please do any solution by this program?
Your existing for i=1:height(dummy) loop would be fine if you were to use readtable, with the exception that you should change the test to
if dummy.OperationResult(i)==" Read OK"
Rewriting to use readtable:
function [EPClist,data]=extraction_data(Nomfichier)
dummy = readtable(Nomfichier);
j=1;
for i=1:height(dummy)
if strtrim(dummy.OperationResult(i)) == "Read OK"
data_raw(j,1)=dummy.Date(i);
data_raw(j,2)=dummy.EPC(i);
data_raw(j,3)=dummy.ReadData(i);
j=j+1;
end
end
clear dummy
EPClist=unique(data_raw(:,2));
Nb_capteur=length(EPClist);
data=cell(1,Nb_capteur);
for i=1:Nb_capteur
k=1;
for j=1:length(data_raw)
if data_raw(j,2)==EPClist(i)
%data{i}(k,1)=data_raw(j,1);
%data{i}(k,1)=0;
data{i}(k,1)=hex2dec(data_raw{j,3}(5:8));
temphexa=data_raw{j,3}(9:12);
if temphexa(1)=='F'
data{i}(k,2)=1/100*(hex2dec(temphexa)-hex2dec('FFFF')+1);
else
data{i}(k,2)=1/100*hex2dec(temphexa);
end
k=k+1;
end
end
EPClist{i}=EPClist{i}(end-3:end);
end
This has three differences compared to your original:
  • changed importfile() to readtable()
  • changed ' Read OK' to "Read OK"
  • added strtrim()
I wanted to account for the possibility that when you used readtable() that possibly the leading space in ' Read OK' might not be present. Either way, whether it is or is not present, this code should work.
There is one potential problem, though: with readtable() the Date might be read as a datetime object rather than as numeric; if so then you would not be able to mix it in with numeric objects. But possibly it will come across as a char vector or as a cell array of char vectors or as a string... it would be easier if we had an extract of a file to test with.
function [EPClist,data]=extraction_data(Nomfichier)
dummy = readtable(Nomfichier);
j=1;
for i=1:height(dummy)
if strtrim(dummy.OperationResult(i)) == "Read OK"
data_raw(j,1)=dummy.Date(i);
data_raw(j,2)=dummy.EPC(i);
data_raw(j,3)=dummy.ReadData(i);
j=j+1;
end
end
clear dummy
EPClist=unique(data_raw(:,2));
Nb_capteur=length(EPClist);
data=cell(1,Nb_capteur);
for i=1:Nb_capteur
k=1;
for j=1:length(data_raw)
if data_raw(j,2)==EPClist(i)
%data{i}(k,1)=data_raw(j,1);
%data{i}(k,1)=0;
data{i}(k,1)=hex2dec(data_raw{j,3}(5:8));
temphexa=data_raw{j,3}(9:12);
if temphexa(1)=='F'
data{i}(k,2)=1/100*(hex2dec(temphexa)-hex2dec('FFFF')+1);
else
data{i}(k,2)=1/100*hex2dec(temphexa);
end
k=k+1;
end
end
EPClist{i}=EPClist{i}(end-3:end);
end
Here i copy paste totally your program and it shows this error :
>> extraction_data1
Not enough input arguments.
Error in extraction_data1 (line 2)
dummy = readtable(Nomfichier);
it is resolved. Thank you
You have to pass in a file name.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Calendar 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by