how to create a class with some properties?

Hi everybody,
could you please assist me to create a class in with some properties?
I want to create two communication channel (paths) and want to call on the basis of their properties.
path_1_properties:
data_rate = 10 mbps
delay = 250 ms
loss rate = 1%
path_2_properties:
data_rate = 1.5mbps
delay = 50 ms
loss rate = 1%
could anyone please help me to have somesuggestion to make a class or list with these properties please.
Thank you in advance.

 Accepted Answer

4 Comments

@Mohmmad Abu Yousuf, and if the above is not good enough for you, then please explain exactly what it is you're not understanding as your question appears very simple. The answer to your question appears to be:
classdef comm_channel %don't call it path as it will clash with matlab path function
properties
data_rate;
delay;
loos_rate;
end
end
Thank you very much for you reply.
As well as could you please tell me that if I want to call those 2 different channel regarding my coding, do I need to call them differently?
I mean is it possible to keep those 2 channel properties in a same class like 'struct'.
As well as could you please help me, how can I call a class to a function?
Thank you in advance.
classes and structures are two different things. It doesn't sound like you fully understand OOP so I recommend you read the documentation and possibly grab a book.
You can create as many instances of the class as you want and name it whatever you want:
path1 = comm_channel;
path2 = comm_channel;
You can create class methods (function). In fact, if your class has no method, it's very much pointless (unless it's a base class for other classes). If you don't have class methods, then indeed a structure would be simpler.
Thank you Guillaume,
truely speaking, I am not very much familiar with OOP.
actually I want to create path1 and path2 with those properties (data rate, delay, loss rate) individually so when I will use anyone of them with a formula then it will automatically take those properties.
like,
for path1,
path1.bandwidth = window size/ delay %window size is predetermined value
so when I will call path1 it will automatically assign the values to the formula. and same for path2.
thank you again.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!