Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: cell array dimensions do not match
Replies: 4   Last Post: Dec 12, 2012 10:42 PM

 Messages: [ Previous | Next ]
 bartekltg Posts: 55 Registered: 12/11/12
Re: cell array dimensions do not match
Posted: Dec 12, 2012 10:42 PM

W dniu 2012-12-13 02:34, Alex pisze:
> Thanks, but that didnt quite work either. With those changes I got the
> error ??? Error using ==> rmfield at 21
> FIELDNAMES must be a string or a cell array of strings.
>
> Error in ==> remover at 33
> deltaT = rmfield(data, toremove)

Hmm, it works in my minimal example:

for j=1:5,
data(j).a1=rand(1);
data(j).a2=-rand(2);
data(j).a7=rand(2);
data(j).a11=rand(12);
end
toremove = {'a2';'a7';'a11'};
data2=rmfield(data,toremove);
disp(data2)

I also recreated (tip for next time. Try to create minimal
code, witch cause problem. I don't have your files:)

listremove = []
toremove = {}

for j=1:5,
data(j).a1=rand(1);
data(j).a2=-rand(2);
data(j).a3=-rand(2);
data(j).a4=-rand(2);
data(j).a5=rand(3);
data(j).a7=rand(2);
data(j).a6=-rand(2);
end

stem = 'a';
for L = 1:6
field = [stem,int2str(L)];
if L>2
rmvr = 1
listremove = [listremove L];
end
end
if rmvr == 1
for g = 1:length(listremove)
field = [stem,int2str(listremove(g))]
toremove = [toremove;field]
end
deltaT = rmfield(data, toremove)
end

It works.

BTW, if you always have structures with these same fields,
and you need faster code, listen to TideMan and use stucture
of vectors.

http://stackoverflow.com/questions/7274268/which-is-faster-vector-of-structs-or-a-number-of-vectors

c++, but some information apply to matlab.

bartekltg

Date Subject Author
12/12/12 Alex
12/12/12 bartekltg
12/12/12 Alex
12/12/12 bartekltg
12/12/12 Derek Goring