How to find the maximum length in a structure of vectors?

20 ビュー (過去 30 日間)
AXL
AXL 2017 年 11 月 11 日
回答済み: AXL 2017 年 11 月 12 日
I have a struct, fem. One of its field is a cell (fem.Element) and I want to find the maximum length of fem.Element.
Thanks in advance, André

採用された回答

AXL
AXL 2017 年 11 月 12 日
I solved using this: max(cellfun(@length,fem.Element);

その他の回答 (1 件)

Precise Simulation
Precise Simulation 2017 年 11 月 12 日
If by "maximum length" you mean the number of struct entries, then you can just use one of the standard length, numel, or size commands
length(fem)
numel(fem)
size(fem)
If you mean the maximum value in each struct entry you could use something like
mx_all = cellfun(@max,struct2cell(fem))
mx = max(mx_all(:))
  2 件のコメント
AXL
AXL 2017 年 11 月 12 日
編集済み: AXL 2017 年 11 月 12 日
I mean the maximum length in one struct field. I can use this because not all the fields are struct and I get the message:
% Non-scalar in Uniform output, at index 3, output 1. Set 'UniformOutput' to false.
AXL
AXL 2017 年 11 月 12 日
I solved it using this: max(cellfun(@length,fem.Element);
But really thanks! I'm not used to work with cells.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by