Undefined function/variable with function

조회 수: 11 (최근 30일)
Anita Sinha
Anita Sinha 2021년 4월 6일
댓글: Adam Danz 2021년 4월 6일
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?

채택된 답변

Adam Danz
Adam Danz 2021년 4월 6일
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
Anita Sinha
Anita Sinha 2021년 4월 6일
Yes, I changed some variables before posting the code here. I realized that in my main script, I should have called the function as
[c_3darray, p_3darray] = load_data(control_dir, patient_dir);
Adam Danz
Adam Danz 2021년 4월 6일
The output variable names aren't the problem, though.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by