Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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});

Risposta accettata

Jan
Jan il 1 Mar 2017
Modificato: Jan il 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.

Più risposte (0)

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by