Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
bartekltg

Posts: 31
Registered: 12/11/12
Re: cell array dimensions do not match
Posted: Dec 12, 2012 10:42 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.