How change values in n number of matrix?

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.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 20일
편집: Azzi Abdelmalek 2013년 5월 20일

0 개 추천

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}
%or use eval, which is not recommanded
s='A':'N'
for k=1:numel(s)
eval([s(k) '(5,5)=50'])
end
José-Luis
José-Luis 2013년 5월 20일

0 개 추천

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);

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 5월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by