Hi Carl Narup,
1. u get access to the cell arrays with {}
2. if you want to compare strings use strcmp
MPcell1 = {'a', 'e', 'q', 't', 'w', 'q', 't', 'a', 'b', 'a'};
unic = {'a', 'q', 'w'};
-------------------------
function totsum = songsum(MPcell1, unic, c)
numb_artists = length(unic);
unic(2,:) = cell(1,numb_artists);
for i = 1:numb_artists
unic{2,i} = sum(strcmp(MPcell1,unic{1,i}));
end
end
strcmp compares all elements of MPcell1 at once with each element of unic and returns a logical array (with 1 if true and 0 if false)
sum adds up all 1s to the total number of succesfull hits
But be careful, if you are not used to use logical operations on matrices the result (or further comparisons) might surprise you.
1 Comment
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/359825-function-input-and-output#comment_490276
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/359825-function-input-and-output#comment_490276
Sign in to comment.