Matrix Size Changing in a loop

1 visualización (últimos 30 días)
Burak
Burak el 26 de Mzo. de 2017
Comentada: KSSV el 27 de Mzo. de 2017
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
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 Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by