I keep getting "Array indices must be positive integers or logical values". error
Show older comments
Heres my code, why do I get the error?
clc
clear
% Given values
L = 0.05;
qL = -100-(4.6611*5);
qR = -300+(0.3869*5);
x = linspace(0,0.05,5);
%% Requirement 4
V = zeros(length(x),1);
Vx1(0:(L/2)-1)=1;
Vx2((L/2):L) = (((qR-qL)*x.^2)/L)+((2*qL-qR)*x)-((L/4)*(qL+qR));
Accepted Answer
More Answers (1)
Steven Lord
on 22 Oct 2022
0 votes
There is no element 0 in an array in MATLAB. The first element is element number 1. You will need to change the line of code that creates the variable Vx1.
You also cannot reference or assign to an element at a fractional index. There is no element 0.05 or 0.025 in MATLAB. Therefore you will also need to change the line that creates the variable Vx2.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!