Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Need Help in the following code, Subscript indices must either be real positive integers or logicals?

1 vue (au cours des 30 derniers jours)
arun
arun le 28 Juin 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Need help for the following code, i'm getting subscript indices error..
if true
% sample_ind = cell(1,NumAct);
OneActionSample = zeros(1,NumAct);
for i = 1:NumAct
action = TargetSet((i-1)*2+1:i*2);
action_dir = strcat(file_dir,action,'\');
fpath = fullfile(action_dir, '*.mat');
depth_K2_dir = dir(fpath);
ind = zeros(max_subject,max_experiment);
for j = 1:length(depth_K2_dir)
depth_K2_name = depth_K2_dir(j).name;
sub_num = str2double(depth_K2_name(6:7));
exp_num = str2double(depth_K2_name(10:11));
ind(sub_num,exp_num) = 1;
load(strcat(action_dir,depth_K2_name));
depth_K2 = depth_K2(:,:,frame_remove+1:end-frame_remove);
[front, side, top] = depth_K2_projection(depth_K2);
front = resize_feature(front,fix_size_front);
side = resize_feature(side,fix_size_side);
top = resize_feature(top,fix_size_top);
TotalFeature(:,sum(OneActionSample)+j) = [front;side;top];
end
OneActionSample(i) = length(depth_K2_dir);
sample_ind{i} = ind;
end
TotalFeature = TotalFeature(:,1:sum(OneActionSample));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% You may consider to save the training and testing samples for speed.
% save(strcat(ActionSet,'.Features.mat'), 'TotalFeature');
%
% Load the feature file if there isn't going to be any changes on the
% feature set.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
Subscript indices must either be real positive integers or logicals.
Error in NewTest2 (line 63) ind(sub_num,exp_num) = 1;
  1 commentaire
José-Luis
José-Luis le 28 Juin 2016
Check the values of sub_num and exp_num. Your problem should then become clearer.

Réponses (1)

Guillaume
Guillaume le 28 Juin 2016
Modifié(e) : Guillaume le 28 Juin 2016
Clearly, you need to learn to use the debugger.
Step through your code and look at the list of file names returned by dir. One of them is not conforming to your expectation that characters 6:7 or 10:11 are strictly positive integers. Since you're converting these characters to numbers and then use these numbers as indices, if this expectation is broken, your program fails.
You can always add a check before using these indices:
...
exp_num = str2double(depth_K2_name(10:11));
if exp_num < 1 || sub_num < 1 || mod(exp_num, 1) ~= 0 || mod(sub_num, 1) ~= 0
%do whatever you want when expectation is broken
warning('file %s does not conform to expectations. Skipping', depth_K2_name);
continue;
end
ind(sub_num,exp_num) = 1;
...
  2 commentaires
arun
arun le 28 Juin 2016
Please tell the reason for the following error in general..
Error using * Inner matrix dimensions must agree...
Guillaume
Guillaume le 28 Juin 2016
What has this got to do with your original question? Your code does not even have a multiplication that could generate this error.
With such an unspecific question, the only reason I can provide is that the inner matrix dimensions don't agree (as the error message tells you).
Perhaps, you meant to use .* instead of *. Who knows?

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by