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

1 view (last 30 days)
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

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 6 May 2016
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 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 6 May 2016
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 on 7 May 2016
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!