Undefined function/variable with function
6 views (last 30 days)
Show older comments
In my main script, I have the following:
addpath(genpath('...'));
control_dir = '..'
patient_dir = '..'
% function
load_data(control_dir, patient_dir);
in my load_data function:
function [c_3darray, p_3darray] = load_data(control_dir, patient_dir)
controls = fullfile(control_dir, '*.mat');
patients = fullfile(patient_dir,'*.mat');
control_files = dir(controls);
patient_files = dir(patients);
num_roi = 379;
control_3darray = zeros(num_roi, num_roi, length(control_files));
patient_3darray = zeros(num_roi, num_roi, length(patient_files));
for i = 1:length(control_files)
origFilename = control_files(i).name;
fullFilename = fullfile(control_dir, origFilename);
% fprintf(1, '\nProcessing: %s\n', fullFilename);
[filepath, name, ext] = fileparts(fullFilename);
load(fullFilename);
c_3darray(:, :, i) = cov(x);
end
for i = 1:length(patient_files)
origFilename = patient_files(i).name;
fullFilename = fullfile(patient_dir, origFilename);
% fprintf(1, '\nProcessing: %s\n', fullFilename);
[filepath, name, ext] = fileparts(fullFilename);
load(fullFilename);
cov_mat = cov(fullmat_720tr_sc);
p_3darray(:, :, i) = cov(x);
end
end
when I run my main script, I get the error: Undefined function or variable 'control_3darray'. What am I missing here?
0 Comments
Accepted Answer
Adam Danz
on 6 Apr 2021
Given the incomplete error message, it seems that the error is not with the "control_3darray" variable but with x
c_3darray(:, :, i) = cov(x);
In the line above, x is not defined.
Also, c_3darray should probably be control_3darray. Same with p_3darray and patient_3darrayM.
There may be other errors as well but that's all the deeper I looked.
2 Comments
More Answers (0)
See Also
Categories
Find more on Digital Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!