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 件のコメント
José-Luis
2016 年 6 月 28 日
Check the values of sub_num and exp_num. Your problem should then become clearer.
回答 (1 件)
Guillaume
2016 年 6 月 28 日
編集済み: Guillaume
2016 年 6 月 28 日
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 件のコメント
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!