Question

MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...

MATLAB

Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [ word, number] = MaxContent( arr)
%
L = cellfun('length',arr); % here we compute the length
% of the elements in the cell array
[m, i] = max(L);
word = arr(i); % word holds the longest string

fprintf('The longest string is:');
disp(word);

dim = size(arr,1); % get the lenght of the cell array

number = 0;
for i=1:dim
if(L(i) == 1)
if(cell2mat(arr(i))>number)
number = cell2mat(arr(i));
end
else
continue;
end
end

fprintf('Maximum integer is %d',number);
end

Add a comment
Know the answer?
Add Answer to:
MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT