How to generate several matrix by varying one value?
Show older comments
I'm using that code below, and I want to get 6 matrix, according to the value of "i". the problem is that I get only i=15. so just one value of "i", and then one results.
How can I force it to use all the values from i=10 till i=15
for i=10:15;
A= [i 0 0 30 ; 70 30 0 0 ; 30 70 0 0 ; 30 0 70 0];
B= [1; 2; 3; 4];
C = inv(A);
D= A\B;
end
E=bsxfun(@times,i,B)
i
Thank you
Accepted Answer
More Answers (1)
Andrei Bobrov
on 25 Apr 2018
ii = 10:15;
A= [0 0 0 30 ;
70 30 0 0 ;
30 70 0 0 ;
30 0 70 0];
n = numel(ii);
A = repmat(A,1,1,numel(ii));
A(1,1,:) = ii;
s = size(A);
B= [1; 2; 3; 4];
D = zeros(numel(B),n);
C = zeros(s);
es = eye(s);
for jj = 1:n
D(:,jj) = A(:,:,jj)\B;
C(:,:,jj) = A(:,:,jj)\es;
end
E = bsxfun(@times,ii(:),B);
Categories
Find more on MATLAB 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!