フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

is it possible to do something like this in the loop:

1 回表示 (過去 30 日間)
jenka
jenka 2017 年 1 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
if true
% load Time;
Time_test_1 = Time;
clear Time;
%load Time again;
Time_test_2 = Time;
clear Time;
%load time again;
Time_test_3 = Time;
clear Time;
end
  1 件のコメント
Stephen23
Stephen23 2017 年 1 月 13 日
It is possible, but it is a really really bad idea. It is a very bad habit to learn. Naming variables in a loop makes your code slow, buggy, hard to debug, and harder to understand. Read this to know why:
Learn to use indexing rather than make lots of separate variables. Then your life suddenly gets better :)

回答 (1 件)

the cyclist
the cyclist 2017 年 1 月 13 日
編集済み: the cyclist 2017 年 1 月 13 日
Yes, but it is better to use a cell array instead of that naming convention ...
if true
% load Time;
Time_test{1} = Time;
clear Time;
%load Time again;
Time_test{2} = Time;
clear Time;
%load time again;
Time_test{3} = Time;
clear Time;
end
which can easily be looped over ...
for ii = 1:3
% load Time
Time_test{ii} = Time;
clear Time
end
This forum has hundreds of posts about why that is a better way to code.
  3 件のコメント
jenka
jenka 2017 年 1 月 13 日
my Time variable is already a cell array?
Guillaume
Guillaume 2017 年 1 月 13 日
So? You can have cell arrays of cell arrays.
If the cell arrays all have the same number of rows or columns, you could also concatenate them.
Note that I would avoid using load without an output. Rather than:
load('somefile'); %pops the Time variable into existence.
Time_test{idx} = Time;
Use filecontent = load('somefile'); Time_test{idx} = filecontent.Time;
There's no danger of unknowingly overwriting existing variables with the second method.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by