필터 지우기
필터 지우기

Creat 1000 different matrix

조회 수: 1 (최근 30일)
Deepesh Kumar Gupta
Deepesh Kumar Gupta 2021년 9월 25일
댓글: Deepesh Kumar Gupta 2021년 10월 2일
I have 1000 different values of Bi, I want to creat 1000 different C matrix of order (12, 1) , where Each element of (12, 1) , ist matrix contains ist value of Bi and each element of (12, 1) ,2nd matrix contains 2 nd value of Bi. and so on. And each different 1000 matrix will print in Command windows and it's name like C1, C2, C3... C1000.

채택된 답변

Steven Lord
Steven Lord 2021년 9월 25일
Can you define variables with numbered names like C1, C2, C3, ... ? Yes.
Should you do this? Generally we recommend against it. See that page for alternatives you should use instead.
  댓글 수: 13
Stephen23
Stephen23 2021년 10월 1일
편집: Stephen23 2021년 10월 1일
@Deepesh Kumar Gupta: please format your code properly. Badly formatted code discourages people from helping you.
% matrix calculation for i=1:1000 A=zeros(12,12);
for k=1:12
for j=1:12
if j==1
A(k,j)=1./(Rs{i}(k))+Bi(i).*log(Rs{i}(k));
else
A(k,j)=((j-1)*((Rs{i}(k)).^(j-1)+(Rs{i}(k)).^(1-j))./Rs{i}(k)+Bi(i)*((Rs{i}(k)).^(j-1)-(Rs{i}(k)).^(1-j)))* cos((j-1).*g(k));
end
end
end
end
If this code works and you need to repeat it 1000 times, then you can simply nest it inside another loop and either:
  1. assign the matrices to a cell arraz, much like you are already doing for Rs, or
  2. assign the matrices to one ND array.
Give it a try, e.g. cell array (just like Rs):
N = 1000;
C = cell(1,N);
for ii = 1:N
.. your code
C{ii} = your matrix
end
Deepesh Kumar Gupta
Deepesh Kumar Gupta 2021년 10월 2일
Thank you very much @Stephen .this code works

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by