Randomly read in data and feed into fuzzy logic file
2 views (last 30 days)
Show older comments
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.
Accepted Answer
Walter Roberson
on 18 Apr 2018
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 Comments
Walter Roberson
on 18 Apr 2018
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".
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!