How to use Struct Array in a function

2 ビュー (過去 30 日間)
eric heins
eric heins 2017 年 1 月 30 日
回答済み: Walter Roberson 2017 年 1 月 30 日
I have a function, which is opened by the callback openFcn in Simulink. In this function a struct Array is created with the function evalin. The Problem is that this struct Array is saved in the base Workspace and when i try to use the struct Array i get the error message 'Undefined variable "in" or class "in.Data".' How do i save that struct Array in the function Workspace to use it. Would be nice, if someone had an idea about this.
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 30 日
Which function are you hoping the assignment could be written into?
Stephen23
Stephen23 2017 年 1 月 30 日
編集済み: Stephen23 2017 年 1 月 30 日
"The Problem is that this struct Array is saved in the base Workspace"
Accessing variables in the base worksapce will always be slow and buggy. Why bother? Simply learn to pass arguments, write nested functions, or any of the other simple, reliable, and fast ways of passing data between workspaces.
Using evalin does not make your code efficient or reliable:
Much simpler would be to learn how to write functions effectively (e.g. nested functions), and learn the several fast and reliable ways to pass data between their workspaces:
(Hint: do not use global, evalin, assignin, etc)

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 30 日
In the place you need the structure, use
in = evalin('base', 'in') ;

その他の回答 (0 件)

カテゴリ

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