Azzera filtri
Azzera filtri

Error with import data in txt format while generating function

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by