Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

I. Import and export data in a variety of formats

Data Manipulation

 

Import and export data in a variety of formats

Mathematica lets you import data in any format, then manipulate it using powerful and flexible functions.

The following imports a graphic in JPEG format. Unless the file is in one of the directories Mathematica searches by default ($Path), you will have to specify the full path.

 

image1= Import["Largemouth bass.jpg"];

 

The result is a Mathematica expression for the graphic in the specified file. You can display the graphic using Show.

 

 

Show[image1]

 

Export sees the.gif file extension, and exports a GIF version of the image.

 

Export["Fish.gif",image1];

 

Mathematica supports many import and export formats. Import can, for example, get data from a spreadsheet.

 

Import["data.dat","Table"]

{{0.253885,6.12433,-0.0177013},{-0.89551,-0.510361,2.51048},{0.829055,-2.38168,-1.65978}}

Assignment 1/9

 

Import to the Math-file any figure in JPEG format, plot it and write to the hard drive in TIFF format with another name.

 

II. DISPLAY

 

Ÿ Display[channel, graphics] writes graphics or sound to the specified output channel in Mathematica PostScript format.

Ÿ Display[channel, graphics, "format"] writes graphics or sound in the specified format.

Ÿ Display[channel, expr, "format"] writes boxes, cells or notebook expressions in the specified format.

Ÿ The output channel can be a single file or pipe, or a list of them.

Ÿ The graphics in Display can be Graphics, Graphics3D, SurfaceGraphics, ContourGraphics, DensityGraphics or GraphicsArray.

Ÿ The graphics can also include Sound.

Ÿ Any of the graphics formats specified for Export can be used.

The following options can be given:

 

 

Examples:

 

wr1= Display["fig-DeltaC.eps", pic1,"EPS"];

wr2= Display["fig1-DeltaC.bmp", pic2,"BMP"];

 

Assignment 2/9

 

Plot function Sin(x2) in the limits 0 £ x £ 1 and write figure to the hard drive in BMP format by using Display operator.

 

III. For reading and importing the data it is easy to use ReadList operator

 

 

Ÿ ReadList["file"] reads all the remaining expressions in a file, and returns a list of them.

Ÿ ReadList["file", type] reads objects of the specified type from a file, until the end of the file is reached. The list of objects read is returned.

Ÿ ReadList["file", { type1, type2, … }] reads objects with a sequence of types, until the end of the file is reached.

Ÿ ReadList["file", types, n] reads only the first n objects of the specified types.

Ÿ The option setting RecordLists -> True makes ReadList create separate sublists for objects that appear in separate records.

Ÿ ReadList takes the same options as Read, with the addition of RecordLists.

Ÿ If file is not already open for reading, ReadList opens it, then closes it when it is finished. If the file is already open, ReadList does not close it at the end.

Ÿ ReadList prints a message if any of the objects remaining in the file are not of the specified types.

 

Examples:

ReadList[“Command”, Number] run an external command and read in a list of the numbers it produces.

dat1 = ReadList ["D:\Kudfort\Mathfile\CvSchY1.txt", Number, RecordLists -> True ];

dat2 = ReadList [ "CvMyY7.nb", Number, RecordLists -> True ];

dat3 = dat2 /.{x_, y_} - > {x, y ´ 665.379};

fig1= ListPlot[dat1, dat3];

 

 

Assignment 3/9

 

Establish text file (your name.txt) with numerical data

 

0 5.6

1 2.3

2 3.5

3 4.7

4 7.8

5 3.9

 

in your own directory. Read these data in Mathematica file, modify “y” values by dividing on 1.5 and plot resultant data without joining.

<== предыдущая лекция | следующая лекция ==>
 | IV. Writing the data
Поделиться с друзьями:


Дата добавления: 2014-01-11; Просмотров: 337; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.013 сек.