Error with import data in txt format while generating function

3 次查看(过去 30 天)
Hey everybody,
I have a data in txt format includes numbers. I apply following steps, because I don't want to import data each time and I want to use this function in my script:
Home>Import Data>Import Selection>Generate Function
then, Matlab auto-generates me the function.
function Untitled1 = importfile('1.txt');
%IMPORTFILE Import numeric data from a text file as a matrix.
% UNTITLED1 = IMPORTFILE(FILENAME) Reads data from text file FILENAME for
% the default selection.
%
% UNTITLED1 = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
% STARTROW through ENDROW of text file FILENAME.
%
% Example:
% Untitled1 = importfile('1.txt', 1, 200001)
%
% See also TEXTSCAN.
% Auto-generated by MATLAB on 2017/11/17 10:47:41
But it gives me that error:
>> importfile Error: File: importfile.m Line: 1 Column: 33 Unexpected MATLAB expression.
Coloumn:33 is after first paranthesis and before ' sign.
What is the problem?

采纳的回答

Rik
Rik 2017-11-17
The problem is that the input argument name should not be a string. Either call the function with that as the input argument, or hard-code this filename.
%replace this:
function Untitled1 = importfile('1.txt')
%with either this:
function Untitled1 = importfile(filename)
%or this:
function Untitled1 = importfile
filename='1.txt';
  2 个评论
theintern
theintern 2017-11-20
Thank you so much, it works. I am wondering, how can I read value in a coloumn, I mean the 3th coloumn means C value. How can I read it in programme?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by