Cell contents reference from a non-cell array object.

Error in Evaluation (line 67)
U = [U TI(1).Si{a}];
here is my code, how can i fix this error?
T1 = Evaluation( pop,SI,D,N,m,T1,MST,NS)
chr.id=[];
chr.sequence=[];
chr.Si={};
chr.relevant=[];
chr.vic_item = [];
TI=repmat(chr,numel(N/2));
U =[];
for a=1:numel(TI(1).Si)
U = [U TI(1).Si{a}];
end
U = unique(U,'first');
U;

5 commentaires

the cyclist
the cyclist le 16 Nov 2019
Modifié(e) : the cyclist le 16 Nov 2019
There is not enough information here to solve the problem.
Superficially, it looks like it could run. TI(1).Si seems to be a cell array, so referencing its cell contents should work.
I can run this code just fine (if I define a value for N), but it never enters the for loop where the problem occurs.
Can you please post a more complete version of the code, that we can actually run and exhibit the error?
Note that N is probably a scalar numeric value, and numel(N/2) would be the same as numel(N) which would be 1, so your chr would be repeated only once.
the value of N=10 or more than 10
Mira le
Mira le le 17 Nov 2019
Modifié(e) : Mira le le 17 Nov 2019
Is there another method to replace this U = [U TI(1).Si{a}]; ?
Guillaume
Guillaume le 17 Nov 2019
Modifié(e) : Guillaume le 17 Nov 2019
You need to pay attention to the comments you were given. It's very difficult to help you when you provide code that has no comment and doesn't work.
As Walter explained, numel(N/2) is always the same as numel(N). The actual values of N don't matter to know how many elements there are, so dividing the values by 2 doesn't change their count. If N is scalar, whether it's 10, 1 million or 0, numel(N) is 1. so your
T1 = repmat(chr,numel(N/2));
doesn't do anything useful, it's simply
T1 = chr;
As the cyclist explained, with the given code T1.Si (which is chr.Si) is an empty cell array, so numel(T1.Si) is 0 and the loop
for a=1:numel(TI(1).Si)
doesn't even execute once. So the code you've shown cannot produce your error.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Graphics Objects dans Centre d'aide et File Exchange

Question posée :

le 16 Nov 2019

Modifié(e) :

le 17 Nov 2019

Community Treasure Hunt

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

Start Hunting!

Translated by