【发布时间】:2010-10-03 03:13:23
【问题描述】:
我有以下函数,它的最后一个参数是文本文件的名称:
function [property_without_headers]=gslib_file_to_matlab_var(nModel,nCell,gslib_file_name) % must enter the last argument, gslib_file_name, in single quotes as its treated as a string
if nargin<3, % making third argument optional (code to be executed even when only 2 arguments are provided)
gslib_file_name=input('Enter the gslib file name: ','s');
end
if length(gslib_file_name)<4 || ~strcmpi(gslib_file_name(end-3:end),'.dat'),
gslib_file_name=[gslib_file_name '.dat']; % string concatenation
end
%% Reading directly from the .dat files generated from SGEMS and making the data of file as a variable
property_gslib_format=textread(gslib_file_name,'%f\t','headerlines',nModel+2);
property_without_headers=reshape(property_gslib_format,nModel,nCell)';
现在,通过一般的看法,函数的最后一个要输入的参数似乎是数字。 如何让用户更清楚地知道要输入的最后一个参数(文本文件的名称)应该是字符串格式,即单引号?如果我定义了像下面这样的函数然后我得到 Unexpected MATLAB expression. 的错误:
[property_without_headers]=gslib_file_to_matlab_var(nModel,nCell,'gslib_file_name')
【问题讨论】:
标签: string matlab function text-files