Constants that cannot be delete with CLEAR

Simple,
I have some personal constants define in startup.m but every time I type CLEAR in the command window I loose them.
Is there a way to make some constants non deletable ?
Thank you.

 採用された回答

Matt J
Matt J 2023 年 6 月 4 日
編集済み: Matt J 2023 年 6 月 4 日

1 投票

You could make the constants the Constant properties of a class. Then they can be reused even after issuing clear
classdef myconst
properties (Constant)
a=1;b=2;c=3
end
end
>> myconst.a
ans =
1
>> clear
>> myconst.b
ans =
2

その他の回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 6 月 4 日
移動済み: Matt J 2023 年 6 月 4 日

1 投票

You can use this command
clearvars -except VariblesNotToBeDeleted

1 件のコメント

Pierre
Pierre 2023 年 6 月 4 日
編集済み: Pierre 2023 年 6 月 4 日
I little bit too long, imagine I have many constants.

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

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

質問済み:

2023 年 6 月 4 日

編集済み:

2023 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by