MATLAB Answers


How to read text file in object oriented programming ?

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
sampleRate = 1000
function y = readtext(this)
fileID = fopen(this);
C = textscan(fileID,'%f %f %f %f %f %f %f');
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;
As you can see, I would like to read a text with readtext method. How can I overcome with this problem? Thanks

  1 件のコメント

2014 年 7 月 25 日
...How can I overcome with this problem?
And what problem is that, pray tell?

サインイン to comment.

1 件の回答

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
And then you readtext signature should be:
function y = readtext(this,filename)
% this is object, filename is file name.
fid = fopen(filename);
% etc

  0 件のコメント

サインイン to comment.

Translated by