How to empty 1 cell of a cell variable which is part of a file?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
per isakson
2017-12-3
编辑:per isakson
2017-12-3
"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 个评论
per isakson
2017-12-3
编辑:per isakson
2017-12-3
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!