フィルターのクリア

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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by