Why is one ans removed when assigning simulink/matlab?

天涯浪子 提交于 2019-12-13 07:07:34

问题


Why is one ans removed when I assign y? I want to return the two descriptions.

x = rmi('get',gcs)

x = 

2x1 struct array with fields:

    doc
    id
    linked
    description
    keywords
    reqsys

>> x.description

ans =

FirstReq


ans =

SecondRec

>> y = x.description

y =

FirstReq

>> y

y =

FirstReq

回答1:


You probably need to use the {}:

>> x.description

ans = FirstReq

ans = SecondRec

>> y = {x.description}

y =
{
  [1,1] = FirstReq
  [1,2] = SecondRec
}

You can then index into y using either () (output will be a cell array) or {} (output will be whatever the data type of the description field is):

>> y(1)

ans =
{
  [1,1] = FirstReq
}

>> y{1}
ans = FirstReq

Note: I am using Octave, not MATLAB, but it should still apply.



来源:https://stackoverflow.com/questions/17811746/why-is-one-ans-removed-when-assigning-simulink-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!