필터 지우기
필터 지우기

Matrix Size Changing in a loop

조회 수: 4 (최근 30일)
Burak
Burak 2017년 3월 26일
댓글: KSSV 2017년 3월 27일
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
Joshua
Joshua 2017년 3월 27일
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 2017년 3월 27일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by