Subscript indices must either be real positive integers or logicals only in the loop
Show older comments
Dear all,
I'm stuck with the error "Subscript indices must either be real positive integers or logicals." in the code below. When I delete the loops and do manually for different values of i and ii, no error appears. Could you please help to understand what is wrong?
[~, m] = ismember(date30(:,1:5),date_sep2(:,1:5),'rows');
date30_all=NaN(length(date30),size((data),2)+6);
date30_all(:,1:5)=date30(:,1:5);
for i=2:size((date30),1);
date30_all(i,6:end)=out(m(i,1),6:end);
for ii=6:size((date_sep2),2);
if isnan(date30_all(i,ii));
date30_all(i,ii)=out(m(i-1,1),ii);
else
end
end
end
Accepted Answer
More Answers (1)
Walter Roberson
on 10 May 2016
1 vote
m has entries for all of the date30(:,1:5) values, not just the ones that match. m will be 0 for the ones that do not match. You are not testing your m before using them.
The first output of ismember would be a logical vector indicating whether the m was valid or not.
1 Comment
Ekaterina Serikova
on 10 May 2016
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!