How do I use information in mat file?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Linjun He
am 22 Nov. 2018
Kommentiert: Linjun He
am 19 Dez. 2018
Here's the information in each .mat file.(metric, PF, Population)
![eachFile.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196126/eachFile.png)
What I want to do is to use information in .mat file as inputs (PF->PF, Population->PopObj), and store the output (Score->metric) for the following function.
![function.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196128/function.png)
Extension: I have many .mat files like this.How do I handle this in a batch?
![matFile.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196129/matFile.png)
0 Kommentare
Akzeptierte Antwort
Stephen23
am 22 Nov. 2018
Bearbeitet: Stephen23
am 22 Nov. 2018
D = 'path to folder where those files are saved';
S = dir(fullfile(D,'*.mat'));
N = natsortfiles({S.name}); % download from FEX
C = cell(1,numel(N));
for k = 1:numel(N)
T = load(fullfile(D,N{k}));
C{k} = NHV(T.Population,T.PF);
end
This imports all .mat files in the given folder, runs the function NHV on their contents, and stores the function outputs in the cell array C. To get the right file order you can download the function natsortfiles here:
See also:
3 Kommentare
Stephen23
am 22 Nov. 2018
Simpler:
parfor k = 1:10
F = sprintf('IDMOEAD/IDMOEAD_DSDTLZ1_M3_%d.mat',k);
S = load(F);
S.metric = NHV(S.Population.objs,S.PF);
save(F,'-struct','S');
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!