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

1 Ansicht (letzte 30 Tage)
Viswanath Hariharan
Viswanath Hariharan am 2 Dez. 2017
Bearbeitet: per isakson am 3 Dez. 2017
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) = [];

Antworten (1)

per isakson
per isakson am 3 Dez. 2017
Bearbeitet: per isakson am 3 Dez. 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 Kommentare
Viswanath Hariharan
Viswanath Hariharan am 3 Dez. 2017
I want to make A one cell shorter actually.
per isakson
per isakson am 3 Dez. 2017
Bearbeitet: per isakson am 3 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by