本文介绍了MATLAB从向量数组中的struct提取字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:我有一个结构体数组,想从向量中的该结构体中提取一个字段.

I got the following Problem: I got a struct Array and want to extract one field from that struct in a vector.

该结构具有5个字段,其中一个称为名称".如何获得这些向量?

The struct has 5 fields, one which is called "name". How can I get These in a vector?

推荐答案

您可以使用 extractfield方法:

You can make use of the extractfield method:

yourNameFieldsAsArray = extractfield(yourStruct, 'name') 

如果name字段保留例如字符/字符串值,或者如果name字段仅包含例如整数,则为常规值数组.

Where yourNameFieldsAsArray will be a cell array if the name field holds e.g. character/string values, or a regular value array if name field just hold, say, integers.

这篇关于MATLAB从向量数组中的struct提取字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 14:03