필터 지우기
필터 지우기

error using the cellfun function

조회 수: 2 (최근 30일)
Ariela Glikman
Ariela Glikman 2019년 3월 2일
댓글: Star Strider 2019년 3월 2일
Hi guys,I have a cell with names (first.last) and I wrote a function who receives names and checking if they are written correctly.
I'm trying to call the function but there is an error.
function [studBonus] =kahootRes
name= {'Harry.Potter', 'Albu.Dom', 'vold lors'};
ansVec= [1 2 3 3 5 6 0 8 6 6], [1 2 0 4 5 6 0 8 0 6], [1 2 3 4 5 6 0 8 9 6];
fileName= struct('name', name, 'ansVec', ansVec);
fullName= {fileName.name};
[resValid, firstName, lastName]= cellfun(@checkName,fullName); % here is the error
this is the function I wrote, it not really important for you but I add it anyway.
function [resValid, firstName, lastName] = checkName(fullName)
posDot= find(fullName=='.');
countDot = length(posDot);
resValid=0;
firstName=[];
lastName=[];
if (countDot==1)
resValid= 1;
firstName= fullName(1:posDot-1);
lastName= fullName(posDot+1:end);
elseif ((countDot==0)|| (countDot>1))
resValid= 0;
firstName= fullName;
lastName=[];
end

답변 (1개)

Star Strider
Star Strider 2019년 3월 2일
The error I get from the code as you posted it is:
Error using cellfun
Non-scalar in Uniform output, at index 1, output 2.
Set 'UniformOutput' to false.
So, do exactly that, and the error no longer exists:
[resValid, firstName, lastName]= cellfun(@checkName,fullName, 'UniformOutput',false)
or more commonly:
[resValid, firstName, lastName]= cellfun(@checkName,fullName, 'Uni',0)
  댓글 수: 2
Ariela Glikman
Ariela Glikman 2019년 3월 2일
you are genius,
I really don't understand what did you write but its working. thankssד
Star Strider
Star Strider 2019년 3월 2일
My pleasure! Thank you.
If my Answer helped you solve your problem, please Accept it!

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by