Undefined function/variable with function

7 ビュー (過去 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 Center および File ExchangeDigital Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by