help-octave
[Top][All Lists]
Advanced

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

using eval with multiple variable strings


From: Thomas Detman
Subject: using eval with multiple variable strings
Date: Sat, 30 Jan 2010 21:21:19 -0800
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Hi,

I'm starting to feel comfortable with octave, but have never used Matlab, although I always heard good things about it. I can't help with the eval command, but here is what I do to save a plot:

 #...
 Run = "103a" # just a dummy id tag for this example
 #...
 # your plot code here
 #...
 FigId = ["UtsVNT.",Run,".eps"]
 printf ('print (FigId,"-landscape", "-color")\n')

At this point I check the plot in the plot window, and I should see this in
the terminal window:

FigId = UtsVNT.103a.eps
print (FigId,"-landscape", "-color")

If I like what I see, then I just copy and paste that last last line,
right there in the terminal window.

That's a little more complicated than it needs to be; one could just
put the bare print statement in the code, like:

print (FigId,"-landscape", "-color")

But then the plot file get created whether you like it or not.

Seeing that print command in the terminal output could be confusing,
like next year when you dust of the code and run it.  So, you could
do a printf ("copy & paste?\n")

Sarah Caudill 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




reply via email to

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