This is a tutorial question only! There is no need to answer it and please to not vote for it. This is neither my question nor my answer, but only an example for a nicer, more convenient, more usable FAQ, which is less stuffed with commercials.
FAQ: How can I process a sequence of files?
179 ビュー (過去 30 日間)
古いコメントを表示
How can I process a sequence of files?
3 件のコメント
Salah Djerouni
2020 年 2 月 15 日
Hi Jan
can i ask you some question because i have a problem for save result in matlab
my probleme is i run matlab with three loops (for...end ) and i want to save the result every change iterataion loop.
if you possible to help me .
thanks Jan
Walter Roberson
2020 年 2 月 16 日
Pre-allocate an output array that is at least 3 dimensions, with one dimension being the number of times the first loop will execute, a second dimension being the number of times the second loop will execute, and the third dimension being the number of times the third loop will execute. Then assign to the output according to how many loop iterations you have done.
For example,
Lvals = [-83, 149, -5, 0, -2, 101];
numL = length(Lvals);
output = zeros(7, 3, numL);
for J = 9:17:11
Jidx = round((J-9)/17) + 1;
for K = 1000:500:2000
Kidx = round((K-500)/500);
for Lidx = 1 : numL
L = Lvals(Lidx);
output(Jidx, Kidx, L) = J.^2 + K/7 + sin(L.^3);
end
end
end
採用された回答
Jan
2012 年 12 月 26 日
編集済み: Jan
2021 年 4 月 8 日
3 件のコメント
Walter Roberson
2019 年 6 月 23 日
Each iteration in a separate file could result in hundreds of thousands of files.
persistent fid
if isempty(fid) || isempty(fopen(fid))
fid = fopen('output.txt','wt');
end
fprintf(fid, 'appropriate format', appropriate data) ;
joshua Abam
2019 年 6 月 24 日
Hi Walter
I seem not to have follow your suggestion can you help by adding some more comments to ease my grap or better still use this example to illustrate it and where best can I possible attached that to a GA code.
function f = gaintobj(x)
f = rastriginsfcn([x(1)-6 x(2)-13]);
f = f + rastriginsfcn([x(3)-3*pi x(4)-5*pi]);
lb = [1 1 -30 -30];
ub = [20 20 70 70];
%%
% Set the integer variables and number of variables.
IntCon = [1 2];
nvar = 4;
%%
% Set options to call the custom output function, and to initially have
% little crossover.
options = optimoptions('ga','OutputFcn',@gaoutputfunround,'CrossoverFraction',0.2);
%%
% For reproducibility, set the random number generator.
rng(10)
%%
% Set the objective function and call the solver.
fun = @gaintobj;
[x,fval] = ga(fun,nvar,[],[],[],[],lb,ub,[],IntCon,options)
その他の回答 (2 件)
Sean de Wolski
2016 年 7 月 29 日
編集済み: Sean de Wolski
2016 年 7 月 29 日
In MATLAB R2014b and newer, you can use a datastore to read a sequence of files in a load-analyze-discard manner or in one shot with the readall() command.
1 件のコメント
Ismail Qeshta
2017 年 11 月 11 日
Hi all. Thanks for sharing it. How about if my files are in permutations sequence such as, Data11, Data12, Data 13, etc. Also, what if I would like to plot two different files names within a folder? Regards.
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!