Filter löschen
Filter löschen

error using the cellfun function

2 Ansichten (letzte 30 Tage)
Ariela Glikman
Ariela Glikman am 2 Mär. 2019
Kommentiert: Star Strider am 2 Mär. 2019
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

Antworten (1)

Star Strider
Star Strider am 2 Mär. 2019
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 Kommentare
Ariela Glikman
Ariela Glikman am 2 Mär. 2019
you are genius,
I really don't understand what did you write but its working. thankssד
Star Strider
Star Strider am 2 Mär. 2019
My pleasure! Thank you.
If my Answer helped you solve your problem, please Accept it!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by