# Why do I get this error? "indices must either be real positive integers or logicals."

1 visualizzazione (ultimi 30 giorni)
Ani Asoyan il 7 Giu 2020
Commentato: Ani Asoyan il 7 Giu 2020
hi, why do I get this error ?
Subscript indices must either be real positive integers or logicals.
Error in sev (line 27)
N(g) = (q*b-a*d)./(e*(q^2)+g.*2*a)
here's my code..
syms q
a=2; b=2; d=0.5; e=0.9 ; q=0.4;
g=1:0.1:10
N(g) = (q*b-a*d)./(e*(q^2)+g.*2*a)
i(g)=(b-e*q*N)/a
m=N(g)
n=i(g)
figure(1)
plot (g,m,'b')
hold on
plot (g, n,'red')
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

KSSV il 7 Giu 2020
Modificato: KSSV il 7 Giu 2020
You need not to use syms. there is no requirement of syms.
You need not to use indesing N(g), this is not reuqired also this is not valid.
a=2; b=2; d=0.5; e=0.9 ; q=0.4;
g=1:0.1:10
N = (q*b-a*d)./(e*(q^2)+g.*2*a)
i=(b-e*q*N)/a
m=N
n=i
figure(1)
plot (g,m,'b')
hold on
plot (g, n,'r')
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
KSSV il 7 Giu 2020
You have used syms but, you have over written the variable. So it no more a symbolic variable. In the present case g has fractions. MATLAN array indices should always be positive integers. May be in the previous case your array might be integers and so it worked.
Ani Asoyan il 7 Giu 2020
No it wasn't integers. but ok I got it,, Thank you !

Accedi per commentare.

### Più risposte (2)

Image Analyst il 7 Giu 2020
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Ani Asoyan il 7 Giu 2020
thanks

Accedi per commentare.

Maximilian Schönau il 7 Giu 2020
You could use N(g) to create a symbolic function with the symbolic variable g. Since g is not a symbolic variable but a vector, Matlab trys to use the values of g as indices of N, wich does not work.
Use:
N = (q*b-a*d)./(e*(q^2)+g.*2*a)
To create a function N(g) use:
syms g
N(g) = (q*b-a*d)./(e*(q^2)+g.*2*a) % symbolic function
or
N = @(g) (q*b-a*d)./(e*(q^2)+g.*2*a) % function handle
##### 2 CommentiMostra NessunoNascondi Nessuno
Ani Asoyan il 7 Giu 2020
oh sorry I wrote syms q, but it had to be syms g.... but even in that case I still get that error
Ani Asoyan il 7 Giu 2020
It worked, thank you !

Accedi per commentare.

### Categorie

Scopri di più su Numeric Solvers in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!