Creat 1000 different matrix
1 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
Deepesh Kumar Gupta
2021-9-26
Okay Steven, instead of C1, C2.. C1000 you can take C(1), C(2).. C(1000).and please help in this code
Stephen23
2021-9-26
@Deepesh Kumar Gupta: either use a cell array to hold all of those matrices:
or one numeric ND-array:
What did you try so far?
Deepesh Kumar Gupta
2021-9-26
I have to print all 1000 matrix in command window.
Thank you in advance
Deepesh Kumar Gupta
2021-9-26
编辑:Walter Roberson
2021-9-26
c=0.01;
d=.013;
m=1000;
ri=c+(d-c).*rand(m,1);
h=315;
K=44.5;
Bi=(h*ri) /K;
for k=1:1000
C=zeros(12,1)
for i=1:12
C(i,:)=Bi(k)
end
end
Deepesh Kumar Gupta
2021-9-26
I am getting only one (12, 1) matrix, i have to print such 1000 matrix
Stephen23
2021-9-26
c = 0.01;
d = 0.013;
m = 1000;
ri = c+(d-c).*rand(1,m);
h = 315;
K = 44.5;
Bi = (h*ri)./K
Bi = 1×1000
0.0757 0.0807 0.0876 0.0810 0.0781 0.0866 0.0910 0.0856 0.0741 0.0887 0.0910 0.0854 0.0813 0.0713 0.0860 0.0914 0.0905 0.0809 0.0748 0.0788 0.0893 0.0723 0.0761 0.0732 0.0807 0.0917 0.0891 0.0755 0.0741 0.0764
C = num2cell(repmat(Bi,12,1),1)
C = 1×1000 cell array
Columns 1 through 588
{12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double}
Columns 589 through 1000
{12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double} {12×1 double}
C{1} % Checking the first cell
ans = 12×1
0.0757
0.0757
0.0757
0.0757
0.0757
0.0757
0.0757
0.0757
0.0757
0.0757
Deepesh Kumar Gupta
2021-9-26
I am still not able to print C{1} of order (12,1) , can u please be in more details
Steven Lord
2021-9-26
A = {magic(4), ones(2, 3, 4), @sin} % A sample cell array
A = 1×3 cell array
{4×4 double} {2×3×4 double} {@sin}
celldisp(A) % Display all elements of the cell array
A{1} =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
A{2} =
(:,:,1) =
1 1 1
1 1 1
(:,:,2) =
1 1 1
1 1 1
(:,:,3) =
1 1 1
1 1 1
(:,:,4) =
1 1 1
1 1 1
A{3} =
@sin
Deepesh Kumar Gupta
2021-10-1
I have 1000 Rs matrix of order(1,12) and 1000 values Bi .I want to create 1000 A matrix of order (12,12). How can I create A matrix .
% 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
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:
- assign the matrices to a cell arraz, much like you are already doing for Rs, or
- 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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)