help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using eval with multiple variable strings


From: Jaroslav Hajek
Subject: Re: using eval with multiple variable strings
Date: Sun, 31 Jan 2010 06:35:53 +0100

On Sun, Jan 31, 2010 at 2:42 AM, Sarah Caudill <address@hidden> wrote:
> Hello,
>
> I am new to using octave and would like to port some of my matlab
> code. I am using octave version 3.0.1.
>
> I will post my matlab code below. Basically, I am using a function
> called scatter_plots to make a scatterplot. The function inputs
> include a couple of strings that will be used in the naming
> conventions for plot axes, titles, legend, and plot names. I have
> utilized 'eval' multiple times to do this. I also read in two .mat
> files with the signal-to-noise ratio (snr) data that is to be plotted.
>
> The main problem is that the eval statement seems to behave very
> differently in octave. For example, if I set veto_level='CAT2',
> injtype='EOBNR', ifo2='H', and ifo1='L', my plot title using my matlab
> code will be: CAT2 EOBNR: H SNR versus L SNR
>
> Also I am having alot of difficulty figuring out how to save the plot.
> I want to save it as a png and give it a name based on inputs.
> However, it is not obvious to me how to use the octave print command
> with eval so that I can use multiple strings in the the file name.
>
> Thus, I cannot figure out how to use octave's eval statement to take
> in my various string inputs. Maybe I shouldn't be using eval at all.
> Can anyone help me rewrite the code for plotting that I've pasted
> below.
>
> %%%%%%%%%%%%%%%%%MATLAB CODE%%%%%%%%%%%%%%%%%%%%%
> function scatter_plots( veto_level, coinctype, ifotime, ifo1, ifo2,
> data1, data2, injtype)
>
>  % read in the data files
>  eval(['datax=load(''' data1 ''');'])
>  eval(['datay=load(''' data2 ''');'])
>
>  figure
>  loglog(datax.snr, datay.snr, 'kx');
>  grid on
>  eval(['x_lab=xlabel(''\rho_{' ifo1 '}'');'])
>  eval(['y_lab=ylabel(''\rho_{' ifo2 '}'');'])
>  set(x_lab,'FontSize',14);
>  set(y_lab,'FontSize',14);
>  set(gca,'FontSize',14);
>  eval(['plot_title=title(''' veto_level ' ' injtype ': ' ifo2 ' SNR
> versus ' ifo1 ' SNR'');'])
>  set(plot_title,'FontSize',14,'FontWeight','b');
>  eval(['leg=legend(''Background ' coinctype ' coincidence in '
> ifotime ' time'',''Injections ' coinctype ' coincidence in ' ifotime '
> time'',0);'])
>  set(leg,'FontSize',14);
>  eval(['saveas(gcf,''' veto_level '_' injtype '_' ifo1 '' ifo2
> '_H1H2L1_H1H2L1_snrscatterplot.png'')'])
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>

I don't think any of these tasks requires eval.
For instance,

eval(['datax=load(''' data1 ''');'])
-->
datax = load (data1);

eval(['x_lab=xlabel(''\rho_{' ifo1 '}'');'])
-->
x_lab = xlabel (sprintf ("\\rho_{%s}", ifo1));

etc.

I don't think that stuff like legend, gcf etc. will work with 3.0.1. I
recommend you upgrade to 3.2.x.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]