フィルターのクリア

varagin with original var names

3 ビュー (過去 30 日間)
Polsak Tothong
Polsak Tothong 2023 年 7 月 1 日
編集済み: Stephen23 2023 年 7 月 1 日
Hi,
Is it possible to carry or parse original variable names into the function using varargin
tout = zProcess( aa, bb, cc)
function [ tdata] = zProcess( varargin)
% a way to parse varargin into aa, bb, cc
  1 件のコメント
Stephen23
Stephen23 2023 年 7 月 1 日
編集済み: Stephen23 2023 年 7 月 1 日
"Is it possible to carry or parse original variable names into the function using varargin"
That would be a very bad way to write code:
The whole point of functions is that they are a black box: what happens inside should be irrelevant. For example, do you know what internal variable names the SQRT function uses? No, you don't. Imagine if SQRT only worked with one particular input variable name, that would be a horrendously user-unfriendly function. Ugh.
What you are proposing throws away most of the benefits of using functions. Why would you want to do that?
In any case, this question is a good example of
Instead of asking us about your attempted solution, you should describe what the actual goal is: what kind of data do you have and how do you need to process it? Forget about magically naming variables like that, unless you really want to force yourself into writing slow, complex, buggy, inefficient, obfuscated code that is hard to debug. Best avoided.

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

採用された回答

Paul
Paul 2023 年 7 月 1 日
inputname can be used to return the name of the variable in the calling workspace as a character vector, at least for simple calling cases. What would you do with the results from inputname?
[aa,bb,cc] = deal(0);
tout = zProcess( aa, bb, cc);
s = 'aa'
s = 'bb'
s = 'cc'
function [ tdata] = zProcess( varargin)
for ii = 1:numel(varargin)
s = inputname(ii)
end
tdata = 1;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by