Matlab的:计数具有特定内容结构的数 [英] Matlab: Count number of structs that have a specific content

查看:154
本文介绍了Matlab的:计数具有特定内容结构的数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理Simulink设计验证,并想提取我自己的一些信息。因此,我要算目标的数量,以及其中多少得到满足。

'目标'是一个结构本身:目标< 1×10结构>

计数的目标数很简单:

 长度(字段名(目标))

的'目标'的内容也是结构。每一个这样的结构有下面的内容:

 键入状态标签

现在我想指望有多少元素'目标'满足财产

 '状态==满意


解决方案

假设你有结构的数组,请使用以下code:

  NNZ(STRCMP({} Objectives.status,满意))

如果你有旧matlab版,你可以使用:

  NNZ(strmatch('满意',{} Objectives.status,精确))

I'm dealing with Simulink Design Verifier and want to extract some information on my own. Therefore, I want to count the number of Objectives and how much of them have been satisfied.

'Objectives' is a struct itself: Objectives<1x10 struct>

Counting the number of objectives is easy:

length(fieldnames(Objectives))

The content of 'Objectives' are also structs. Each such struct has the following content:

type

status

label

Now I want to count how many elements in 'Objectives' satisfy the property

'status == Satisfied'

解决方案

Assuming that you have an array of structs, use the following code:

 nnz(strcmp({Objectives.status},'satisfied'))

If you have old Matlab version, you can use:

 nnz(strmatch('satisfied',{Objectives.status},'exact'))

这篇关于Matlab的:计数具有特定内容结构的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆