How change values in n number of matrix?
Show older comments
Hello, I am a beginner in programming. I have a task where for example, i have 30 matrices all being a 10x10 matrix
A=[] B=[] C=[] . . . N=[]
And now i am interested in changing a55 element to one value maybe '50' in all the matrices. How can i write a code for this. Or is there a function that I can use?
Thank you in advance.
Answers (2)
Azzi Abdelmalek
on 20 May 2013
Edited: Azzi Abdelmalek
on 20 May 2013
Instead of working with A,B,C, you should work like below
A=rand(5);
B=rand(5);
C=rand(5)
YourArray={A,B,C}
YourArray{1} % is A
YourArray{2} % is B
YourArray{3} % is C
% to make changes
for k=1:numel(YourArray)
YourArray{k}(5,5)=100
end
YourArray{1}
s='A':'N'
for k=1:numel(s)
eval([s(k) '(5,5)=50'])
end
José-Luis
on 20 May 2013
You could create this function:
function [varargout] = change_value(varargin)
varargout = cell(numel(varargin));
for ii = 1:numel(varargin)
varargin{ii}(55) = 50;
varargout(ii) = varargin(ii);
end
And then call it as follows:
A=rand(10);
B=rand(10);
C=rand(10);
[A B C] = change_value(A,B,C);
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!