Matrix Size Changing in a loop

Hi, I need to calculate a matrix say A(v,n,m) like this code
for n=1:5
m=-n:n;
for v=1:5
for i=1:numel(m)
A(v,n,i)= % my function
end
end
end
now A is a 5x5x11 matrix, but I want to calculate A as a changing matrix size like for m=1 , A=10x10 for m=2 A=9x9, for m=3 A=8x8, same as for negative values of m. Because I need to inverse of A, and I can't inverse for all m values if I calculate like my code. How can I do that , I don't want to calculate it separately. Thanks for any help.

3 comentarios

Burak
Burak el 27 de Mzo. de 2017
I did search my previous question in matlab and in my account tab , I couldn't find so I posted it again. Sorry. For my question , lets say
for n=1:5
m=-n:n;
for v=1:5
A(v,n,i)=v*n-m(i);
end
end
end
for i=1:11
Ai(:,:,i)=inv(A(:,:,i));
end
Like this I can't inverse it. I found a solution , I placed all A variables in a cell array then I removed zeros from it and I can inverse it in a cell array but it is really challenging , I am asking if there is another way to calculate A's in changing size in every loop. Thanks for the concern.
Joshua
Joshua el 27 de Mzo. de 2017
From what I understand, you want to create a 3D array which holds matrices of different sizes in the 3rd dimension. Then, you want to invert each of these matrices ignoring the extra zeros. I think I found a solution.
clear
clc
num=11;
m=-3:3;
for i=1:numel(m)
for v=1:num-m(i)
for n=1:num-m(i)
A(v,n,i)= rand(1);
end
end
Ai(1:num-m(i),1:num-m(i),i)=inv(A(1:num-m(i),1:num-m(i),i));
end
num is an arbitrary scaling variable (so m(i)=1 makes 10x10, m(i)=2 makes 9x9, etc.). Also, I replaced your function with the rand function because your function was making non-invertible matrices every time. Take a look at matrices A and Ai and see if it what you are looking for.
KSSV
KSSV el 27 de Mzo. de 2017
With m=-n:n; the indices in matrix A(v,n,i) will be negative and your code stops popping out a error. You are not clear with your question.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Mzo. de 2017

Comentada:

el 27 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by