In an assignment A(I) = B, the number of elements in B and I must be the same error.

조회 수: 1 (최근 30일)
Hello, I am trying to make a script to use in some analysises but I have this "In an assignment A(I) = B, the number of elements in B and I must be the same" error. I think it is a common error. My codes are shown below. I have 3 data sets and it worked it 2 of them but the 3rd one giving that error to me. Error is in the line "N(j)=find(M~=0)". When I try to run the code, I=6042 logical, K=[31;32;33;34;35] , M=1095 logical, N=[109,250,486,744,750,1004], i=9 and j=4. I attached my data as .mat file. I have no idea why this code is not working. I really need help.
Good day
for i=1:numel(Full_Result.Nodes_Names)
I=strcmp(Full_Result.Nodes_Names{i, 1},Network.Nodes);
Full_Result.Nodes_NEdges(i)=sum(I);
%Listedeki Hangi metabolitlerle eşlesiyor
K=find(I~=0);
Full_Result.ESC{i,1}=Network.Edges(K',1);
for j=1:numel(K)
M=strcmp(Network.Edges{K(j),1},Pvalues.Edges);
N(j)=find(M~=0);
end
%Calculate the aggregated Z-score for the metabolite
Full_Result.Nodes_ZScores(i)=sum(Pvalues.Zscores(N))/sqrt(numel(N));
Full_Result.Nodes_meanZ(i)=mean(Pvalues.Zscores(N));
Full_Result.Nodes_stdZ(i)=std(Pvalues.Zscores(N));
end

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
load error_matrixes
for i=1:numel(Full_Result.Nodes_Names)
I=strcmp(Full_Result.Nodes_Names{i, 1},Network.Nodes);
Full_Result.Nodes_NEdges(i)=sum(I);
%Listedeki Hangi metabolitlerle eşlesiyor
K=find(I~=0);
Full_Result.ESC{i,1}=Network.Edges(K',1);
N=cell(1);
for j=1:numel(K)
M=strcmp(Network.Edges{K(j),1},Pvalues.Edges);
N{j}=find(M~=0);
end
%Calculate the aggregated Z-score for the metabolite
Full_Result.Nodes_ZScores(i)=sum(Pvalues.Zscores(N{j}))/sqrt(numel(N));
Full_Result.Nodes_meanZ(i)=mean(Pvalues.Zscores(N{j}));
Full_Result.Nodes_stdZ(i)=std(Pvalues.Zscores(N{j}));
end
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
If find(M~=0) gives just one value you can write N(j)=find(M~=0) but if the result have different sizes, for example find(M~=0) gives [1 3]; then [4 5 7], what is the meaning of?
N(1)=[1 3]
N(2)=[4 5 7]
Hamza Karakurt
Hamza Karakurt 2016년 5월 7일
The main problem for me is that those codes worked for 2 data sets but didn't work for a data set that exact have same format. What could be the difference?

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by