Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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});

Réponse acceptée

Jan
Jan le 1 Mar 2017
Modifié(e) : Jan le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by