필터 지우기
필터 지우기

How can I find a string in an array of strings? Error using strfind PATTERN must be a string scalar or character vector.

조회 수: 7 (최근 30일)
Dear all,
I am currently trying to derandomize a list of filenames. I do have a derandomization sheet for this. However, whenever I am trying to run the script I wrote for this I encounter the following error:
Error using strfind
PATTERN must be a string scalar or character vector.
Error in Derandomization (line 14)
idx = find(~cellfun(@isempty,strfind(N,C)))
This is my code:
clearvars
close all
basicpath = ('C:\path');
[~,~,raw] = xlsread('filenames_new_sheet.xlsx');
T = readtable('derandomization.xlsx');
t = T{:,'Filename'}
newStr = erase(t,'_kakaka'); %get body of filenames to match
C = unique(newStr) % delete filenames that exist more than once
N = raw(:,2); runr
j = size(C)
k = size(N)
for n = 1:j
for m = 1:k
idx = find(~cellfun(@isempty,strfind(N,C)))
end
end
>> class N
ans =
'char'
>> class C
ans =
'char'
Why do I keep getting this error message everytime? And what can I do to avoid it? Thank you, everyone.
Kindly
  댓글 수: 8
Stephen23
Stephen23 2020년 5월 6일
@Hannah_Mad: please upload the some sample variables (e.g. raw and T) or the original files, and please show or describe the expected output for those exact variables/files.
Image Analyst
Image Analyst 2020년 5월 12일
Hannah, again I think you misunderstood Stephen's comment. When he said "please upload the some sample variables (e.g. raw and T) or the original files" he meant to attach 'Effekte_der_DBS_korrigiert.xlsx' or 'DDK_acoustic_durations.xlsx' using the paper clip icon. And I'm not seeing those anywhere on this page on any of your posts. We'll check back later for them.

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

채택된 답변

Image Analyst
Image Analyst 2020년 5월 5일
Try contains(). Not sure what derandomize means. Do you mean sort according to some vector of values or alphanumerically?
  댓글 수: 5
Image Analyst
Image Analyst 2020년 5월 12일
But Hannah, I think you misunderstood. Stephen was merely pointing out the differences between ismember() and contains(). ismember() does not search substrings, while contains() does search substrings. So again, I ask did contains() work for you?

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

추가 답변 (1개)

Hannah_Mad
Hannah_Mad 2020년 5월 12일
Thank you, contains () did work for me.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by