mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Added matlab code samples.
All of these code samples currently are mis-identified in my repositories. I'm donating them to the cause.
This commit is contained in:
27
samples/Matlab/par_text_to_struct.m
Normal file
27
samples/Matlab/par_text_to_struct.m
Normal file
@@ -0,0 +1,27 @@
|
||||
function par = par_text_to_struct(pathToFile)
|
||||
% function par = par_text_to_struct(pathToFile)
|
||||
% Returns a structure of the parameters that were stored in a csv text file.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% pathToFile : string
|
||||
% Path to a text file containing the benchmark parameters for a single
|
||||
% bicycle. The parameters should be on seperate lines and take this form:
|
||||
%
|
||||
% c = 0.08+/-0.01
|
||||
% lam = 0.31
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% par : structure
|
||||
% A structure containing the bicycle parameters.
|
||||
|
||||
fid = fopen(pathToFile);
|
||||
data = textscan(fid, '%s %s', 'delimiter', '=');
|
||||
fclose(fid);
|
||||
names = strtrim(data{1});
|
||||
vals = strtrim(regexp(data{2}, '+/-', 'split'));
|
||||
for i = 1:length(names)
|
||||
v = vals{i};
|
||||
par.(names{i}) = str2num(v{1});
|
||||
end
|
||||
Reference in New Issue
Block a user