Is it possible to declare a char variable as global?

4 ビュー (過去 30 日間)
Roberta Piacentini
Roberta Piacentini 2021 年 11 月 11 日
コメント済み: Roberta Piacentini 2021 年 11 月 12 日
Hi everyone,
I would like to declare a char variable as global in order to use it in different functions; more specifically, I want the fit option
opts.Normalize
to be 'on' or 'off' when I specify it, so I thought to create a global variable
global N
N = 'on'
and call N in the fitting function:
opts.Normalize = N;
but the command window gives me error. What can I do?
Thenk you very much

採用された回答

dpb
dpb 2021 年 11 月 11 日
Seems to work just fine here -- although globals are fraught with danger, if you're cautious the above usage doesn't seem too egregious although I don't see too much to be gained by the two steps of setting the global variable and then setting the fitoptions object variable over just setting the option itself.
>> opts=fitoptions
opts =
Normalize: 'off'
Exclude: [1×0 double]
Weights: [1×0 double]
Method: 'None'
>> global N
>> N='on';
>> opts.Normalize=N
opts =
Normalize: 'on'
Exclude: [1×0 double]
Weights: [1×0 double]
Method: 'None'
>>
  3 件のコメント
dpb
dpb 2021 年 11 月 11 日
Good catch, @Steven
Roberta Piacentini
Roberta Piacentini 2021 年 11 月 12 日
Thank you both!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by