I am wokring in the app designer and is trying to run a function on cell array using cellfun function. I am running it on a cell array of file names I got from the uiinput function.
The function is defined in the metode section and is (I have tried with both with and without the first input ( ~/app):
function startend = commonnames(~,cell1,cell2)
cell1 = cell2mat(cell1);
cell2 = cell2mat(cell2);
commonLen = min(length(cell1),length(cell2));
lodicalarrayfwd = ~(cell1(1:commonLen) == cell2(1:commonLen));
lodicalarraybck = ~(cell1(end-(commonLen-1):end) == cell2(end-(commonLen-1):end));
startend = [find(lodicalarrayfwd,1)-1,((commonLen-1)-find(lodicalarraybck,1,'last'))];
The call I am making is:
[app.file,app.path,idx] = uigetfile('*.csv','Select all the applicable csv files','MultiSelect','on');
if idx == 0
startend = cell2mat(cellfun(@commonnames, app.file, app.file(end:-1:1),'UniformOutput',false));
startend = min(startend)
testfile = cell2mat(app.file(1));
startend = [14,9];
testfile = app.file;
The error I am getting is "Error using cellfun : Undefined function 'commonnames' for input arguments of type 'char'."
I am guessing the issue is that a function defined in the methode section need app as first input (at least else it shows up wiht an error), but you can't pass the app using the cellfun function.
I have tried deleting the ~ input and just run as function startend = commonnames(cell1,cell2) but that doesn't work either and I get the same error.
I have run the function in a regular script and there it runs without issue, so I am guessing it is connected to the app designer.
is that app designer simple not compatiable with cellfun unless you use a anonymous function? or is there something I am missing here?