Save vector to class properties

Greetings,
I am trying to build a class that would extract information from .csv files and save these information to the properties of the class. Attached is the example of the file.
Here are my code:
classdef post_processing
properties
data_folder = 'path\path'
filename
time
voltage
norm_voltage
record_length
state_level_high
state_level_low
end
methods
function extract_info(obj)
addpath(obj.data_folder);
filename = 'test.csv';
data = readmatrix(filename);
horizontal_offset = data(6,2); %seconds
sample_interval = data(2,2);%seconds
record_length = data(1,2); %points
time = data(:,4)-horizontal_offset; %seconds
voltage = data(:,5); %volt
norm_voltage = data(:,5)/max(data(:,5));%arb. units
obj.time = time;
obj.voltage = voltage;
obj.norm_voltage = norm_voltage;
obj.record_length = record_length;
end
end
end
I called my script:
test = post_processing;
extract_info(test);
test
give output
I do not know why my properties are not updated when I called my extract_info function.
Thanks for the help.

 采纳的回答

addpath(obj.data_folder);
filename = 'test.csv';
Bleh. You should use
filename = fullfile(obj.data_folder, 'test.csv');
With regards to your main question: you are not deriving from handle class, so you are defining a value class. You need to assign the output of the methods over top of the object:
obj = extract_info(obj);

1 个评论

filename = fullfile(obj.data_folder, 'test.csv');
Neat.
That works. Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Octave 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by