Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Preventing unwanted variables being saved in .mat file

Asked by John

John (view profile)

on 16 Mar 2012

Hi there,

I am using the code below to create a .mat file.

In the .mat file it is saving

  1. fn
  2. k
  3. nrows
  4. sch_cycle
  5. sch_grade
  6. sch_key_on
  7. sch_metadata
  8. x

How could I make it only save these only?

  1. sch_cycle
  2. sch_grade
  3. sch_key_on
  4. sch_metadata
x = cellstr(ls('*.xls'));
for k = 1:length(x)
sch_cycle=xlsread('C:\Autonomie practice\cycle.xls','Input_data');
nrows = size(sch_cycle,1);
sch_grade=[0,0;nrows,0];
nrows = size(sch_cycle,1);
sch_grade=[0 0;nrows 0];
sch_key_on=[0 1; nrows 1];
[~,fn] = fileparts(x{k});
sch_metadata.name = fn;
sch_metadata.proprietary='public';
save([fn,'.mat']);
end

Thank you

0 Comments

John

John (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Jonathan Sullivan

Jonathan Sullivan (view profile)

on 16 Mar 2012
Accepted answer
save([fn,'.mat'],'sch_cycle','sch_grade',sch_key_on','sch_metadata');
help save
doc save

3 Comments

John

John (view profile)

on 16 Mar 2012

Hello Jonathan,

Thank you for your reply. I tried this but I'm getting an error.

??? Error using ==> save
Argument must contain a string.

Error in ==> revised_convertfiles at 12
save([fn,'.mat'],'sch_cycle','sch_grade',sch_key_on','sch_metadata');

Would you know what is causing this?

John

Jan Simon

Jan Simon (view profile)

on 16 Mar 2012

The leading quote before sch_key_on is missing.

John

John (view profile)

on 16 Mar 2012

Thanks, I should of seen that!

Jonathan Sullivan

Jonathan Sullivan (view profile)

Contact us