Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

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…

  1. 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);

  2. Assistant

    The variable P_cyc will contain the product of P and G_1 for non-zero elements of G_1.

  3. User

    为什么ind无法正常运行

  4. 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 the find function as follows:

    ind = find(G_1 ~= 0);
    

    Make sure that you have correctly defined G_1 before running this code to avoid any errors.