How do I add a value in ONE element of a matrix in a for loop?
Show older comments
Hello, let's say I have a matrix A = [1+x,1;2,5] so I want to have x to go from -20 to 20 with x~=0
then I would need to have A(i) matrices with i=40 . How do I do this on Matlab? I've been reading on internet on indexing and things like that, but I keep getting errors. I really appreciate you taking the time.
Sincerely,
Accepted Answer
More Answers (1)
This should not require a for loop:
x = [-20:-1, 1:20].';
Amatrices = arrayfun(@(X) [1+X, 1; 2, 5], x, 'UniformOutput', false);
Categories
Find more on Loops and Conditional Statements 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!