Randomly read in data and feed into fuzzy logic file

조회 수: 2 (최근 30일)
Alex kew
Alex kew 2018년 4월 18일
댓글: Alex kew 2018년 4월 18일
Hi, I am new to Matlab, and I have 2 questions.
1. I have a text file, it has 50 lines, each line has a value(e.g. 23). Now I want to randomly read one line, which means read one number randomly from this text file by using a control.m file, and feed into another fuzzy logic file (fuzzy.fis), which function should I use to achieve this goal?
2. In Matlab, do we have functions? like in Java we got method, which can be called within one class, and one class can contain many methods, do we have this kind of structure in Matlab?
Thanks for your answers.

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 18일
1) I do not recommend reading lines at random until the datasets become fairly large and the reading is going to happen a number of times. I recommend instead that you read all of the data and then index into the data randomly at need.
2) yes, MATLAB supports creating classes with methods. The primary keyword to look for is "classdef"
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 4월 18일
No. It is possible to create static methods of a class that do not require instantiation of an object. The route you described is the most typical, but it is not strictly required.
The kind of situation that you outlined would probably be served by coding the class constructor to permit a file name. But if the point were to immediately pull the data out of the resulting object then a static method would make more sense.
In the case where you want to put together libraries of functionality (for example a library of routines that read in various file formats and convert them to image arrays, then you could consider instead creating a MATLAB "package".
Alex kew
Alex kew 2018년 4월 18일
I see, I will try it out.
Thanks again for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by