Path: news.mathworks.com!not-for-mail
From: "Dan Haeg" <haegd@msoe.edu>
Newsgroups: comp.soft-sys.matlab
Subject: hgload script vs commandline
Date: Mon, 7 Jul 2008 21:56:02 +0000 (UTC)
Organization: Milwaukee School of Engineering
Lines: 43
Message-ID: <g4u3di$2ir$1@fred.mathworks.com>
Reply-To: "Dan Haeg" <haegd@msoe.edu>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1215467762 2651 172.30.248.35 (7 Jul 2008 21:56:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 7 Jul 2008 21:56:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 475291
Xref: news.mathworks.com comp.soft-sys.matlab:478039



I have some fig files saved with data I wish to put in
excel. I used hgload in a loop to open the fig files and
retrieve the x-data and y-data. I have trouble when I try to
get the title string of the current axes in a script. It
works fine from the commandline though. I am just wondering
why it does not work, I only had 6 figures to convert so the
commandline workaround was ok but in the future I may need
to use similar code so I want to know the correct way to do it.
Thanks for any advise you can give.
Dan Haeg

Here is the code I tried:

range1 = {'a1','c1',etc};%title range
range = {'a2','c2',etc};%header range
RANGE = {'a1','c1',etc};%raw data range
s=dir('*.fig');

%trying to tell matlab variable types
tit='trial';
ff1='trial';
x=1;y=1;

for ind=1:length(s)
    h=hgload(s(ind).name);
    [x,y]=getfigdatakemp;%a function to retrieve x-data and
          %y-data from the current figure

    %below must be run from the commandline
    h1=get(gca,'title');
    tit=get(h1,'string'); %title string
    ff1=sprintf('%s',tit');
    for lame=1:10 %stupid way to remove extra spaces
        ff1=strrep(ff1,'  ',' ');
    end
    %here I run the above code at the commandline
    keyboard

    xlswrite('raw.xls',{ff1},1,range1{ind})
    xlswrite('raw.xls',{'flow','dp'},1,range{ind})
    xlswrite('raw.xls',[x',y'],1,RANGE{ind})
end
winopen('raw.xls')