Filter löschen
Filter löschen

Error with import data in txt format while generating function

3 Ansichten (letzte 30 Tage)
theintern
theintern am 17 Nov. 2017
Kommentiert: theintern am 20 Nov. 2017
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?

Akzeptierte Antwort

Rik
Rik am 17 Nov. 2017
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 Kommentare
theintern
theintern am 20 Nov. 2017
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 am 20 Nov. 2017
I have also solved this problem, thank you so much for your helps.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by