I have some tabular data with variable names for the columns in my main file. I am passing the tables as variables into methods in a class. In those methods, I wish to be able to access and edit the tabular data according to the variables. How can I do this?
Here is the section of code in my main file (T_n, T_l and period are previously set)
% Get data
lab_Data = readtable(file_lab, 'FileType', 'text');lab_Data.Properties.VariableNames = {'Time', 'Flow', 'P_diff', 'Vol_ex'};nalm_Data = readtable(file_nalm,'Sheet', sheet_name{4});nalm_Data.Properties.VariableNames = {'Time', 'P_diff', 'Flow', 'Vol_tid'};%Run tests
test1 = Tester(nalm_Data, lab_Data, T_n, T_l, period);fileTrimmer(test1);setFile(test1);
The construction of test1 is successful using a simple constructor. However, the other methods don't run and the error message appears to be directed at my attempt to access variables according to their names.
Here is a sample of my "fileTrimmer" code
function fileTrimmer(obj) ... %trim nalm to first peak
f_nalm = obj.nalm_Data.Flow; t_nalm = obj.nalm_Data.Time; [~, loks] = findpeaks(f_nalm, t_nalm, 'MinPeakDistance', obj.period/2); p1 = loks(1); % seconds of first peak.
Here is the constructor
classdef Tester properties sam_rate = .05 %Errors for FlowLab
erFLflow = .05 %(sl/min)
erFLvol = .01 %sl
erFLdp = .1 %mbar
erFLfreq = 1 %bpm
erFLcomp = 1 %ml/mbar
newFile nalm_Data lab_Data T_n T_l period end methods function obj = Tester(nalm_Data, lab_Data, T_n, T_l, period) obj.nalm_Data = nalm_Data; obj.lab_Data = lab_Data; obj.T_n = T_n; obj.T_l = T_l; obj.period = period; fprintf("Tester worked\n"); end
Edit: I actually managed to get around this issue by accessing table data by column indice rather than by their names, so as such have bypassed the error. I definately am still interested to know why it didn't work initially as well as whether it's best to use a value or handle class.
Best Answer