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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by