An indexing expression on the left side of an assignment must have at least one subscript. ???
13 views (last 30 days)
Show older comments
Hi! I keep getting the error: "An indexing expression on the left side of an assignment must have at least one subscript." on my code:
function myMultProd=x(v)
n_vec()=zeros(1, length(x));
for i=1:length(x)
n=x(i);
for j=1:i
n=x(j)*n;
end
n_vec(i)=n;
end
print n_vec;
end
Can someone help me pleaaaase? :)
0 Comments
Answers (1)
Walter Roberson
on 15 Jan 2019
Edited: Walter Roberson
on 15 Jan 2019
n_vec = zeros(1, length(x));
By the way: are you sure that you want x(i) to be multiplied twice in the expression? Once when you initialize n=x(i) and once when j=1:i reaches j=i ?
2 Comments
Walter Roberson
on 15 Jan 2019
function pj = myMultProd(x)
You should have another look at your code. When i = 4, then you would do
n <- x(4) which is n <- 2
j <- 1
n <- x(1) * n which is n <- 2 * 2 which is n <- 4
j <- 2
n <- x(2) * n which is n <- 3 * 4 which is n <- 12
j <- 3
n <- x(3) * n which is n <- 4 * 12 which is n <- 48
j <- 4
n <- x(4) * n which is n <- 2 * 48 which is n <- 96
See Also
Categories
Find more on Matrix Indexing 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!