У меня есть массив ячеек 12X1, который содержит строки символов в каждой ячейке.Я также определил четыре строковые переменные и хочу добавить их в конец массива ячеек, чтобы он стал массивом 16X1.Ниже я разместил свой код о том, как добавить четыре переменные;но я стараюсь выучить этот язык как можно лучше, и мне любопытно, есть ли более «изящный» способ добавления этих переменных, чем то, что я написал.
elseif (ext == '.s3p')
%Read in file to be analyzed; convert to string format so
%that the strsplit function can be used
inFile = textread(thisFile, '%s', 'delimiter', '\n'); %#ok<DTXTRD>
strForm = string(inFile);
cellOut = arrayfun(@(x) strsplit(x, ' '), strForm, 'UniformOutput', false);
%Find the end of the meta data and where the Option line of
%the .s3p file begins (denoted by a '#'). Convert Option
%line to string for parsing.
metaDataEndLine = find(~cellfun(@isempty, strfind(inFile, 'Measurements'))) - 1; %#ok<STRCLFH>
opLine = find(~cellfun(@isempty, strfind(inFile, '#'))); %#ok<STRCLFH>
opStr = cellstr(cellOut{opLine});
%Generate meta-data character strings to be printed to the
%output file. File format can be generalized such that each
%column corresponds to spefied data unit (i.e. frequency is
%always the second col).
metaFreq = opStr(1,2);
metaParam = opStr(1,3);
metaFormat = opStr(1,4);
metaResist = opStr(1,6);
%Genereate a cell array that houses the up-front data
%provided by the file. Remove unnecessary chars.
metaDataPrintFile = strForm(1:metaDataEndLine);
metaDataPrintFile = cellfun(@(x)erase (x, '!'), metaDataPrintFile, 'UniformOutput', false);
metaDataPrintFile = cellfun(@(x)erase (x, 'Correction: '), metaDataPrintFile, 'UniformOutput', false);
%Add data to the class array metaPrint. Append string
%variables generated above.
this.metaPrint = metaDataPrintFile;
this.metaPrint{length(this.metaPrint) + 1} = strcat('Freq = ', metaFreq);
this.metaPrint{length(this.metaPrint) + 2} = strcat('Parameter = ', metaParam);
this.metaPrint{length(this.metaPrint) + 3} = strcat('Format = ', metaFormat);
this.metaPrint{length(this.metaPrint) + 4} = strcat('Input Resistance = ', metaResist);
end %if
Кроме того, если вы видите что-то еще, что я мог бы сделать, чтобы мой код стал более эффективным, я весь слух!
Заранее спасибо и, пожалуйста, дайте мне знать, если естьдругая дополнительная информация, которую я могу предоставить.