我怎么能一个Matlab阵列复制到结构的数组的领域 [英] How can I copy a Matlab array to a field of an array of structs

查看:195
本文介绍了我怎么能一个Matlab阵列复制到结构的数组的领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经定义结构的数组如下:

  T3(1:num_elems)=结构('prime_idx',0,'second_idx',0);

我想一个数组网​​卡复制到T3的prime_idx领域,让 T3(x)的.prime_idx ==网卡(X )对于所有的x。我试过:

  t3.prime_idx =网卡;


     [t3.prime_idx] =网卡;

     t3.prime_idx = [NIC];

     [t3.prime_idx] = [网卡];

和加入各种排列(:)这两个数组变量后 T3 NIC

如何复制网​​卡来T3的相应元素的相应的 prime_idx 字段<?每一个元素/ p>

解决方案

这位前pression S.F,其中S是一个结构的阵列的,结果在一个逗号分隔的列表。因此,写入 SF = X; 是无效的,而 [北京] = X; 会的工作,但需要X来返回尽可能多的输出,S有项目。你需要的是提供这些产出,例如像这样的:

  CNIC = num2cell(NIC);
[t3.prime_idx] = {网络中心:};

I have defined an array of structs as follows:

t3(1:num_elems) = struct('prime_idx',0,'second_idx',0,);

I would like to copy an array nic to the prime_idx field of t3, so that t3(x).prime_idx == nic(x) for all x. I've tried:

 t3.prime_idx = nic;

and [t3.prime_idx] = nic; and t3.prime_idx = [nic]; and [t3.prime_idx] = [nic];

and various permutations of adding (:) after the two array variables t3 and nic.

How can I copy each element of nic to the corresponding prime_idx field of the corresponding element of t3?

解决方案

The expression s.f, where s is a struct array, results in a comma separated list. Thus, writing s.f = x; is invalid, and [s.f] = x; would work, but requires x to return as many outputs as s has items. What you need is to provide those outputs, e.g. like this:

cNic = num2cell(nic);
[t3.prime_idx] = cNic{:};

这篇关于我怎么能一个Matlab阵列复制到结构的数组的领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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