Link to home
Start Free TrialLog in
Avatar of libertyforall2
libertyforall2Flag for United States of America

asked on

Matlab scatter plot in batch mode on linux

I have it installed matlab on a linux box but I have not used matlab that often and never in a linux environment. Do you know what commands I would need to execute matlab? Also, would you happen to have a script for a simple scatter plot. If I have a data file with a simple set of numbers. Two sets of numbers, predicted values and measured values. Two scatter plots, one for so2 and one for aerosols. There would also be a time value per hour. Not clear on how to go about this on a linux box. Lets assume I can create a data file with 3 columns, first column is a date with the year, month, day, hour in 2010101012 format for Today's date at 12noon local time.  Second column, predicted values of so2, third column is measured values of so2. What unix commands would I need to execute to 1, open matlab, 2, import data file, 3, convert columns to arrays (or whatever term used to create graphic), 3 turn arrays into scatter plot (With a title that says measured vs. predicted so2 values, so2 levels on the y axis, date on the x axis, and green for measured red for predicted.)
         In windows, I could simply import a data file then use the graphical features to set the data columns as arrays that could be turned into a line on the scatter plot. I have only used matlab a few times so I am just barely familiar with it. PLEASE HELP!!!
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of libertyforall2

ASKER

Ok. I have been able to pull up matlab in both point click and terminal only mode. Since I will running the scripts in batch mode, I will need some unix shell script to automatically import the file text files. Creating the shell script to modify and create files should not be difficult, but I need to figure out the command on the matlab terminal mode to import text files. Additionally, I will have 2 sets of graphics, one with 8 locations and one with 3. Assuming I am working on the graphic with eight, the text files will be in this format. The data points are in three hour increments.

Date/time, Predicted, Measured
201010100102,28,27
201010100105,29,30
201010100108,32,33
201010100111,38,21




[rhuff@huina ~/hysplit]$ matlab -nosplash -nodisplay

                            < M A T L A B (R) >
                  Copyright 1984-2010 The MathWorks, Inc.
                Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                              February 5, 2010

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
>> demo
??? Error using ==> demo at 23
demo is not supported because Java is not currently available.
 
>> helpwin
??? Error using ==> helpwin at 39
The helpwin command is not supported because Java is not currently available.
 
>> helpdesk
??? Error using ==> doc at 59
The doc command is not supported because Java is not currently available.

Error in ==> helpdesk at 10
doc;
 
>> 

>> [dstr, p, m] = textread('so2.txt','%s %f %f','delimiter',',','headerlines',1); % read datafile
>> dnum = datenum(d,'yyyymmddHH'); % convert date to number
??? Undefined function or variable 'd'.
 
>> 
>> % plot and save
>> plot(dnum,p,'r-o')
??? Undefined function or variable 'dnum'.
 
>> hold on
>> plot(dnum,m,'g-o')
??? Undefined function or variable 'dnum'.
 
>> hold off
>> title('Measured vs. Predicted so2 values')
>> datetick('x','mm/dd/yyyy')
>> legend({'Predicted','Measured'})
Warning: Plot empty.
> In legend at 294
>> saveas(gca,'scatter.png')
------------------------------------------------------------------------
       Segmentation violation detected at Wed Oct 13 12:45:37 2010
------------------------------------------------------------------------

Configuration:
  MATLAB Version:   7.10.0.499 (R2010a)
  MATLAB License:   203706
  Operating System: Linux 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64
  GNU C Library:    2.5 stable
  Processor ID:     x86 Family 6 Model 10 Stepping 5, GenuineIntel
  Virtual Machine:  Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
  Default Encoding:  ISO-8859-15

Fault Count: 1

[  0] 0x00002adabd684789 /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00522121 fl::sysdep::linux::unwind_stack(void const**, unsigned long, unsigned long)+000009
[  1] 0x00002adabd62e94b /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00170315 fl::diag::stacktrace_base::capture(unsigned long)+000027
[  2] 0x00002adabe5e0aa2 /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00330402
[  3] 0x00002adabe5e108e /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00331918
[  4] 0x000000375480e7c0                             /lib64/libpthread.so.0+00059328
[  5] 0x0000003753c30265                                   /lib64/libc.so.6+00197221 gsignal+000053
[  6] 0x0000003753c31d10                                   /lib64/libc.so.6+00204048 abort+000272
[  7] 0x0000003753c6a84b                                   /lib64/libc.so.6+00436299
[  8] 0x0000003753c722ef                                   /lib64/libc.so.6+00467695
[  9] 0x0000003753c7273b                                   /lib64/libc.so.6+00468795 cfree+000075
[ 10] 0x00002adac357c3e1 /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwhg.so+02573281 std::_Rb_tree<std::string, std::pair<std::string const, void*>, std::_Select1st<std::pair<std::string const, void*> >, std::less<std::string>, std::allocator<std::pair<std::string const, void*> > >::_M_erase(std::_Rb_tree_node<std::pair<std::string const, void*> >*)+000145
[ 11] 0x00002adac357c38d /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwhg.so+02573197 std::_Rb_tree<std::string, std::pair<std::string const, void*>, std::_Select1st<std::pair<std::string const, void*> >, std::less<std::string>, std::allocator<std::pair<std::string const, void*> > >::_M_erase(std::_Rb_tree_node<std::pair<std::string const, void*> >*)+000061
[ 12] 0x00002adac3579997 /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwhg.so+02562455
[ 13] 0x0000003753c3368e                                   /lib64/libc.so.6+00210574 __cxa_finalize+000142
[ 14] 0x00002adac3478603 /share/apps/matlab/R2010a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwhg.so+01508867

If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/ts/help_request_1.html

A technical support engineer might contact you with further information.

Thank you for your help.
Sorry I made a mistake in the second line.
Here how it should be.

Please try to understand what each line is doing. What are variables and how they passed between commands.
[dstr, p, m] = textread('so2.txt','%s %f %f','delimiter',',','headerlines',1); % read datafile
dnum = datenum(dstr,'yyyymmddHH'); % convert date to number

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok. It looks like I am going to make a simpler scatter plot. It will have only two values. Measured and Forecasted. It should look something like the file attached. I opened matlab and entered the text above and nothing happened.

[rhuff@huina ~]$ matlab -nosplash -nodisplay

                            < M A T L A B (R) >
                  Copyright 1984-2010 The MathWorks, Inc.
                Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                              February 5, 2010

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
>> [dstr, p, m] = textread('so2.txt','%s %f %f','delimiter',',','headerlines',1); % read datafile
>> dnum = datenum(dstr,'yyyymmddHH'); % convert date to number
>> 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will try this
partially complete.