Storing output of python call to class
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to make a class that will wrap Python's sigmf module. My first step is to load the sigmf file using a python call and store it for later, but I'm not sure how to store it.
My current class is
classdef SigMF
% Wrapper class for python sigmf module
properties
sigmf
end
methods
function obj = fromfile(obj, filename)
% Create a python sigmffile and store for processing
obj.sigmf = py.sigmf.sigmffile.fromfile(filename);
end
function samples = read_samples(obj, start_idx, count)
% Read a number of samples from a given start index
samples = obj.sigmf.read_samples(pyargs("start_index", int64(start_idx-1), "count", int64(count)));
end
end
end
I'm calling it using
x = SigMF()
x.fromfile("test")
This doesn't fail, but it doesn't store the output, so the call to read_samples doesn't work. I can run it step by step in the command line or a script as
x = py.sigmf.sigmffile.fromfile("test")
x.read_samples(pyargs("start_index", int32(0), "count", int32(100)))
I could make read_samples load the file and read samples, loading the file can be slow for large file sizes, so I'd like to just load it once and access it anytime I need it.
0 comentarios
Respuestas (1)
Neha
el 20 de Nov. de 2023
Hi Trey,
I understand that you want to create a class that will wrap the "sigmf" module from Python. By default, MATLAB classes are value classes. Therefore, any modifications made to a property in a method do not persist unless the function actually returns the modified object as an output argument.
To resolve this, you can reassign the object with the output of the "fromfile" function:
x=x.fromfile("test");
samples=x.read_samples(1, 100);
Another way to avoid this issue would be to inherit the "handle" class:
classdef SigMF < handle
...
end
For more information about the difference between value and handle classes, you can refer to the following documentation link:
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!