Iterating through library of text files (for use with Matlab CODER)

1 次查看(过去 30 天)
Hi, I am writing some code that needs to iterate through text files from a library. I read in the data from the text file (from the library) and I compare it to another dataset and compute the similarities between the two datasets. I was able to get this working within the MATLAB environment, but I have been having issues using this code with MATLAB's built-in C Coder.
I keep getting errors stating that: "Referencing a component from array of non-scalar values is not supported for code generation"
Which is confusing given that the datasets only contain positive scalar values. Here is the code I am trying to use:
function [name, M_FDLS, M_CO, M_CC, M_FDAV] = Spectrum_Match(s, wave)
%%Match
% Reads as input a path to a text file corresponding to the Raman Spectrum
% we wish to identify.
%
% Uses a suite of data matching statistics to compute the % match between
% a sample and all members of a library.
%
%%Error handling
if wave == 514
lib_path = '/Volumes/ROEL/RamanProject/Library_copy/514nm_interp/';
elseif wave == 780
lib_path = '/Volumes/ROEL/RamanProject/Library_copy/780nm_interp/';
else
error('Error: please enter correct library wavelength');
end
%%Read Data and check for matches in library
samp_pre = spectra_read(s);
sz = 0; sz = size(samp_pre,1);
if sz ~= 5866
samp = interp_spectrum(samp_pre);
else
samp = samp_pre;
end
ref = zeros(5866,2);
coder.extrinsic('strcat', 'dir');
lib_files = '';
base = '';
lib_form = strcat(lib_path, '*.txt'); lib_files = dir(lib_form);
name = cell(length(samp),1); M_CC = zeros(length(samp),1);
M_FDLS = zeros(length(samp),1); M_CO = zeros(length(samp),1);
M_FDAV = zeros(length(samp),1);
ind = 1; file = ''; cur_file = ',';
for file = lib_files'
base = file.name; cur_file = strcat(lib_path, base);
ref = spectra_read(cur_file);
name{ind} = file.name;
M_FDLS(ind) = FDLS_Matching(ref, samp);
M_CO(ind) = CO_Matching(ref, samp);
M_CC(ind) = CC_Matching(ref, samp);
M_FDAV(ind) = FDAV_Matching(ref, samp);
ind = ind + 1;
end
end

回答(1 个)

Don Zheng
Don Zheng 2017-7-18
Try changing
for file = lib_files'
to
for i = 1:numel(lib_files)
file = lib_files(i);

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by