How to empty 1 cell of a cell variable which is part of a file?

조회 수: 1 (최근 30일)
Viswanath Hariharan
Viswanath Hariharan 2017년 12월 2일
편집: per isakson 2017년 12월 3일
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) = [];

답변 (1개)

per isakson
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
Viswanath Hariharan
Viswanath Hariharan 2017년 12월 3일
I want to make A one cell shorter actually.
per isakson
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 CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by