フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error inside the function,"Struct contents reference from a non-struct array object"?

1 回表示 (過去 30 日間)
arun
arun 2017 年 1 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Error in split_train_test (line 11) idx_label = find(dataset.label == i);
tr_num = 240;
field = 'label';
value = {tottrainlabel};
dataset = struct(field,value);
class_num = length(unique(dataset.label));
fr_dat_split = split_train_test(F, tr_num,class_num);
function dataset_split = split_train_test(dataset, tr_num, class_num)
if nargin < 3
class_num = length(unique(dataset.label));
end
tr_idx = [];
tt_idx = [];
for i = 1 : class_num
idx_label = find(dataset.label == i);
num = length(idx_label);
idx_rand = randperm(num);
tr_idx = [tr_idx idx_label(idx_rand(1 : tr_num))];
tt_idx = [tt_idx idx_label(idx_rand(tr_num+1 : end))];
end

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 10 日
Your call
fr_dat_split = split_train_test(F, tr_num, class_num);
is not passing the dataset into the function: it is passing some other variable, F instead. F is not a structure, whatever it is.
  2 件のコメント
arun
arun 2017 年 1 月 10 日
I made the changes you told, but the function produces another error
Index exceeds matrix dimensions.
Error in split_train_test (line 15)
tr_idx = [tr_idx idx_label(idx_rand(1 : tr_num))];
Walter Roberson
Walter Roberson 2017 年 1 月 10 日
Some of your classes do not have as many as 240 samples.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by