필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
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개)

Guillaume
Guillaume 2016년 6월 28일
편집: Guillaume 2016년 6월 28일
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
arun
arun 2016년 6월 28일
Please tell the reason for the following error in general..
Error using * Inner matrix dimensions must agree...
Guillaume
Guillaume 2016년 6월 28일
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?

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by