Creat 1000 different matrix

1 Ansicht (letzte 30 Tage)
Deepesh Kumar Gupta
Deepesh Kumar Gupta am 25 Sep. 2021
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.

Akzeptierte Antwort

Steven Lord
Steven Lord am 25 Sep. 2021
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 Kommentare
Stephen23
Stephen23 am 1 Okt. 2021
Bearbeitet: Stephen23 am 1 Okt. 2021
@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 am 2 Okt. 2021
Thank you very much @Stephen .this code works

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by