clear ; tic; format long; H=zeros(3,3,3,3,3,3); for s1i=1:3 for s1f=1:3 for s2i=1:3 for…
- User
clear ; tic; format long;
H=zeros(3,3,3,3,3,3); for s1i=1:3 for s1f=1:3 for s2i=1:3 for s2f=1:3 for s3i=1:3 for s3f=1:3 H(s1i,s2i,s3i,s1f,s2i,s3f)=c(s1i,s2i,s3i,s1f,s2f,s3f); end end end end end end
G=zeros(3,3,3,5,5); for s1i=1:3 for s2i=1:3 for s3i=1:3 for s4i=1:5 for s4f=1:5 G(s1i,s2i,s3i,s4i,s4f)=G_value(s1i,s2i,s3i,s4i,s4f); end end end end end
P=1; G_1=G(:,:,:,2:4,1); ind=find(G_1~=0); P_cyc=P*G_1(ind);
- Assistant
The variable
P_cycwill contain the product ofPandG_1for non-zero elements ofG_1. - User
为什么ind无法正常运行
- Assistant
Apologies for the confusion. It seems that there is an error in the code.
To find the indices of non-zero elements in
G_1, you can use thefindfunction as follows:ind = find(G_1 ~= 0);Make sure that you have correctly defined
G_1before running this code to avoid any errors.