Clear Filters
Clear Filters

Error: subscript indices must either be real positive integers or logicals.

3 views (last 30 days)
Hello,
this part of function doesn't working and I don't have any idea why.
hA=axes;
hold on
for i=1:length(Data)
hL(i)=plot(hA,Data(i).x,Data(i).y);
set(hL(i),'LineWidth',LW{i});
end
If I type this code in command window it work perfectly. If I use it as part of function it return:
Subscript indices must either be real positive integers or logicals.
Error in plotGraph (line 144)
set(hL(i),'LineWidth',LW{i});

Accepted Answer

Jan
Jan on 1 Mar 2017
Edited: Jan on 1 Mar 2017
It seems like you have created a variable called "set". Then the arguments are treated as indices and the string causes the error:
set = rand(100, 100, 3)
set(hL(i), 'LineWidth', LW{i});
% ^ Bad index!
The solution is easy: Do not use "set" as name of a variable.
To check if this is the problem, let Matlab stop, when the error occurs: Type this in the command window and run your code again:
dbstop if error
Now check:
which set -all
I guess, the topmost result is a local variable, and not Matlab's built-in function.

More Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!