Find the longest array in an array of vectors

30 次查看(过去 30 天)
I have 5 vectors y1, y2, y3, y4, y5 of variable number of samples or values. I have created a cell array as:
vectorarray = {y1, y2, y3, y4, y5}
I know the classic way of finding the largest number of samples in the elements of the cell array can be done as follows:
maxsamples = 0
for k = 1:numel(vectorarray)
currveclength = length(vectorarray{k})
if currveclength > maxsamples
maxsamples = currveclength
end
end
Is there a simpler way to do it in a single line in Matlab?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-10-9
编辑:Ameer Hamza 2020-10-9
[max_val, idx] = max(cellfun(@numel, vectorarray))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by