how to batch save and load loop variable
5 ビュー (過去 30 日間)
古いコメントを表示
Hello, everyone
I want to access the result of each calculation in the loop calculation I would like to ask if MATLAB has any instructions for batch storage and batch input of variables? and I want to make each stored variable have a different name
ex code
for i = 1:3
a = rand(1,10)
end
a =
0.5817 0.5337 0.8386 0.3502 0.3441 0.9860 0.8664 0.5777 0.2776 0.2758
a =
0.2768 0.5556 0.1333 0.3556 0.8931 0.9569 0.0273 0.2038 0.2547 0.7161
a =
0.2658 0.2586 0.4210 0.5831 0.6447 0.0349 0.2437 0.3171 0.3266 0.4875
I want to convert each generated a into a mat file and be able to read these three sets of a to matlab
Because using normal access will be overwritten because the name is all a
1 件のコメント
Stephen23
2022 年 6 月 19 日
"Because using normal access will be overwritten because the name is all a"
Only if you write code that overwrites that variable.
"I want to make each stored variable have a different name"
That would be a very complex and inefficient approach, whereas you could just use simple and efficient indexing.
What is stopping you from using basic indexing?
回答 (2 件)
KALYAN ACHARJYA
2022 年 6 月 19 日
編集済み: KALYAN ACHARJYA
2022 年 6 月 19 日
#Cell Array cell
a=cell(1,3);
for i = 1:3
a{i}=rand(1,10)
end
Once strore in the cell array, you can do/access data in easiest & efficient way.
0 件のコメント
Voss
2022 年 6 月 19 日
How about making a a matrix?
a = zeros(3,10);
for i = 1:3
a(i,:) = rand(1,10);
end
disp(a);
Or, if each iteration produces a vector of a different length, make a a cell array:
a = cell(3,1);
for i = 1:3
a{i} = rand(1,randi(10));
end
disp(a);
There is no need to make several variables; use one variable (matrix, cell array, etc.) and index into that.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!