フィルターのクリア

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 Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by