when I use contains function in a loop it show me that error message, even though Raw is a cell array, and also the compilation complete and the code after if contains(Raw(i,2),serie)==1 works well.
is there a solution for that ?

댓글 수: 5

Matt J
Matt J 2019년 4월 22일
편집: Matt J 2019년 4월 22일
I suggest you provide code and input data that let's us reproduce the problem.
RMS=cellstr(RMS);
BaseDir = 'C:\Temp'; % Set as you need
[FileName, FilePath] = uigetfile('*.xlsx', ...
'Please choose an Excel file', BaseDir);
File = fullfile(FilePath, FileName);
prompt='Quelle fenêtre ?';
numbofsheet=input(prompt);
[Num, Txt, Raw] = xlsread(File,numbofsheet);
sizeRaw=size(Raw);
for i=2 : sizeRaw(1,1)
if contains(Raw(i,2),serie)==1
for j=2 : rowRMS(1,1)
if contains(Raw(i,1),RMS(j,1))==1
if contains(Raw(i+1,8),MeasTypeID)==1
Raw(i+1,9)=RMS(j,2);
else
if contains(Raw(i+2,8),MeasTypeID)==1
Raw(i+2,9)=RMS(j,2);
else
if contains(Raw(i+3,8),MeasTypeID)==1
Raw(i+3,9)=RMS(j,2);
end
end
end
end
end
end
end
xlswrite(File,Raw,numbofsheet);
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019년 4월 22일
ddaa.PNG
Matt J
Matt J 2019년 4월 22일
편집: Matt J 2019년 4월 22일
You need to provide the variables (in a .mat file) that would let us run the important section of the code as follows:
load yourMATFile.mat
sizeRaw=size(Raw);
for i=2 : sizeRaw(1,1)
if contains(Raw(i,2),serie)==1
for j=2 : rowRMS(1,1)
if contains(Raw(i,1),RMS(j,1))==1
if contains(Raw(i+1,8),MeasTypeID)==1
Raw(i+1,9)=RMS(j,2);
else
if contains(Raw(i+2,8),MeasTypeID)==1
Raw(i+2,9)=RMS(j,2);
else
if contains(Raw(i+3,8),MeasTypeID)==1
Raw(i+3,9)=RMS(j,2);
end
end
end
end
end
end
end
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019년 4월 22일
these are the files

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

 채택된 답변

Adam Danz
Adam Danz 2019년 4월 22일
편집: Adam Danz 2019년 4월 22일

0 개 추천

I can see in your screen shot of workspace variables that your "Raw" array contains mostly NaN values.
According to your error message, the first argument of contains() must be a string array, char vector, or cell array of char vectors. "Raw" appears to be a cell array with lots of NaNs.
You probably want to just skip iterations where the input to contains() includes NaN values (or you might want to use a different method).

댓글 수: 5

AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019년 4월 22일
maybe I understand now
contains works for Raw(2,2); but doesn't work when it find NaN
Yep! One way to avoid iterations with NaNs is something like this:
if all(~isnan(Raw(i,1))) & contains(Raw(i,1),RMS(j,1))==1
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019년 4월 22일
ffddf.PNG
Adam Danz
Adam Danz 2019년 4월 22일
편집: Adam Danz 2019년 4월 22일
You need to do some exploring. Some trial and error. The error message tells you that the input to isnan() does not accept cell arrays. So try this
isnan(out{2,2})
% or
isnan([out{2,2}])
More more information on how to work with cell arrays:
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019년 4월 22일
thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by