How to read text file in object oriented programming ?

5 ビュー (過去 30 日間)
SAMET YILDIZ
SAMET YILDIZ 2014 年 7 月 25 日
回答済み: Sean de Wolski 2014 年 7 月 25 日
Hello, I would like to know how can I read a text or an excel file in the object oriented programming ? I have a simple code like this.
|
classdef diego
properties
column
sampleRate = 1000
end
methods
function y = readtext(this)
fileID = fopen(this);
C = textscan(fileID,'%f %f %f %f %f %f %f');
fclose(fileID);
disp([num2str(this.file),' is the chosen column is',num2str(this.file)]);
disp(['The chosen column of the text file is ',num2str(this.column)]);
y = C;
end
end
end
As you can see, I would like to read a text with readtext method. How can I overcome with this problem? Thanks
  1 件のコメント
dpb
dpb 2014 年 7 月 25 日
...How can I overcome with this problem?
And what problem is that, pray tell?

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 7 月 25 日
The problem is that this, the first input to your function readtext, is the object not the text file. If you want to pass the text file name in, make it the second input:
d = diego
readtext(d,'file.txt')
And then you readtext signature should be:
function y = readtext(this,filename)
% this is object, filename is file name.
fid = fopen(filename);
% etc

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by