how to use passing by value and passing by reference

12 ビュー (過去 30 日間)
RAHUL KUMAR
RAHUL KUMAR 2019 年 10 月 30 日
コメント済み: Walter Roberson 2019 年 10 月 30 日
Basically i have many variables in my code , so i want to use in my function just passing by value and reference. Can anybody tell me with example.

採用された回答

Nicolas B.
Nicolas B. 2019 年 10 月 30 日
I highly recommend you to check the basic types of MATLAB. There is not such thing as a reference in MATLAB. However, for classes, you can create handle classes which works as reference. But then, you can give them by value. If you want to use that feature, read the Comparison of Handle and Value Classes.
Otherwise, if it is just to reduce the number of inputs of a function, you can use structures (or classes).
  3 件のコメント
Nicolas B.
Nicolas B. 2019 年 10 月 30 日
I don't see any way MATLAB could offer you better than structures or classes. But using classes requires to write their descriptions.
Walter Roberson
Walter Roberson 2019 年 10 月 30 日
If the issue is reducing the number of variables passed because passing that many variables is a nuisance, then consider using nested functions with shared variables.

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

その他の回答 (1 件)

James Tursa
James Tursa 2019 年 10 月 30 日
In the background, MATLAB effectively passes all variables into functions as shared data copies. This has the same effect as passing by reference for variables that you don't modify inside the function, i.e. you don't get a deep data copy. Is this what you are asking about?
  2 件のコメント
RAHUL KUMAR
RAHUL KUMAR 2019 年 10 月 30 日
yeah can you provide some example to better understanding
Steven Lord
Steven Lord 2019 年 10 月 30 日
Can you tell us a bit more information about how you've defined your function, how you're trying to call it, and the particular problem / pain / difficulty you're experiencing when trying to call it? With a bit more information we may be able to suggest an easier / faster / "better" solution for calling your function.

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

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by