Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Why wont this run? "Array indices must be positive integers or logical values."

1 Ansicht (letzte 30 Tage)
Steven Butts
Steven Butts am 5 Feb. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
clear all
close all
clc
L =.2;% H
C = 2.0*10^-6; %F
R1 = 1500; %Ohms
R2 = 1000; %Ohms
f = (1/(2*(pi)))*(L*C(((R1^2)*C-L)/((R2^2)*C-L)))^(1/2)
  1 Kommentar
Adam
Adam am 5 Feb. 2020
C(((R1^2)*C-L)/((R2^2)*C-L))
is not sensible code. All that stuff in the parentheses is being interpreted as an index into C, which is scalar anyway, but even if it wasn't I doubt that evaluates to an integer index.
Did you just miss out a * operator?

Antworten (2)

Fangjun Jiang
Fangjun Jiang am 5 Feb. 2020
Most likely typo
f = (1/(2*(pi)))*(L*C*(((R1^2)*C-L)/((R2^2)*C-L)))^(1/2)

Guillaume
Guillaume am 5 Feb. 2020
"Why wont this run? "Array indices must be positive integers or logical values."
The clue is in the error message. Array indices... so you must have some indexing somewhere. Look at your equation:
.. C(((R1^2)*C-L)/((R2^2)*C-L))) ..
yep, you've got C(something). Looking at the something, it's very unlikely to be an integer index. Considering that C is scalar, it's very unlikely you meant to index C. Maybe you're missing an operator?
To make your expression more readable, I would recommend spacing out some terms. I would also recommend against using brackets when they're not needed:
f = 1/(2*pi) * L*C ?? sqrt((R1^2*C - L) / (R2^2*C - L));
%No idea what goes ^ there

Community Treasure Hunt

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

Start Hunting!

Translated by