필터 지우기
필터 지우기

Error with import data in txt format while generating function

조회 수: 3 (최근 30일)
theintern
theintern 2017년 11월 17일
댓글: theintern 2017년 11월 20일
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?
theintern
theintern 2017년 11월 20일
I have also solved this problem, thank you so much for your helps.

댓글을 달려면 로그인하십시오.

추가 답변 (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