function with object as input

Hi, I am trying to write a function that will have the object as input . This is teh code body-
function Tx(obj)
obj.control.signal=zeros(4,1)
obj.cfg.freq=10khz
end
I want to know how to call the function?

4 Kommentare

Rik
Rik am 5 Nov. 2019
The same way you can call any other function? Without a bit more context it is hard to give you more specific advice.
Nafila Farheen
Nafila Farheen am 6 Nov. 2019
Hi Rik,
Thanks for reply. I am new to OOP, so if I want to pass any object as an input to this function, how do I call that? Moreover, it does not have any output? how does if differ from other functions?TIA
Rik
Rik am 6 Nov. 2019
If you want to modify the object, the function should probably return the modified object. Is this meant to be a method in a class?
You should be able to pass your object as an input variable, just like you would with any other function that requires an input.
Walter Roberson
Walter Roberson am 6 Nov. 2019
Note that unless the object is derived from handle class that your code would only modify a temporary copy of the object which would be discarded after the function call. You need to either return the modified version (and store it) or use a handle class.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Performance and Memory finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 5 Nov. 2019

Kommentiert:

am 6 Nov. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by