How do I get the output to only show once, if there is only one output to be shown?
Show older comments
The problem given was "Write a function speciescounts that takes a cell array of species names as input and returns a 2-column cell array with names and frequencies of the species contained in the input. The first column of the output will contain the unique set of species names, in the same order as they appear in the input. The second column of the output will contain the frequency of each species."
My code successfully analyzes the input cell array; however, lets say the input cell array is {'hello' 'hello' 'hello' 'hello'}
it outputs:
'hello' [4] 'hello' [4] 'hello' [4] 'hello' [4]
I would like it to output just:
'hello' [4]
here is what I have so far:
function out = speciescounts(in)
out = cell(numel(in),2);
for i = 1:numel(in)
out{i,1} = in{i};
out{i,2} = numel(find(strcmp(in,in{i})));
end
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!