How to empty 1 cell of a cell variable which is part of a file?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I used matfile to create a 'writable' object consisting of variables in the file. I tried removing an element in one of the variables and I met with the error - "A null assignment can have only one non-colon index." How do I solve this issue? The code is as follows:
A = {};
B = cell(10,1);
save filework.mat A B -v7.3;
exampleobject = matfile('filework.mat', 'Writable', true);
for i = 1:10
B{i} = 2*i;
exampleobject.A(1,i) = B(i,1);
end
exampleobject.A(1,6) = [];
0 commentaires
Réponses (1)
per isakson
le 3 Déc 2017
Modifié(e) : per isakson
le 3 Déc 2017
"How to empty 1 cell of a cell variable" What exactly do you mean by empty? The syntax you use make me think you want to remove one cell to make A shorter.
Replacing
exampleobject.A(1,6) = [];
by
exampleobject.A(1,6) = {[]};
will change the value of one cell to empty.
K>> exampleobject.A
ans =
[2] [4] [6] [8] [10] [] [14] [16] [18] [20]
"A null assignment can have only one non-colon index." says that A(1,6) need to be replaced by A(:,6), but that seems not to work.
2 commentaires
per isakson
le 3 Déc 2017
Modifié(e) : per isakson
le 3 Déc 2017
In R2016a
>> cac = num2cell( [1:12] )
cac =
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]
>> cac(1,6)=[];
A null assignment can have only one non-colon index.
>> cac(:,6)=[]
cac =
[1] [2] [3] [4] [5] [7] [8] [9] [10] [11] [12]
>> cssm
Error using cssm (line 10)
Cannot save an empty array in variable 'A'.
>>
where line 10 of cssm is
exampleobject.A(:,6) = [];
[] is short-hand for "remove", but that doesn't seem to be implemented for mat-file-objects in R2016a. The error message indicates that Matlab tries an assignment.
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!