MATLAB for Behavioral Scientists
eBook - ePub

MATLAB for Behavioral Scientists

David A. Rosenbaum, Jonathan Vaughan, Brad Wyble

Buch teilen
  1. 400 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

MATLAB for Behavioral Scientists

David A. Rosenbaum, Jonathan Vaughan, Brad Wyble

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Written specifically for those with no prior programming experience and minimal quantitative training, this accessible text walks behavioral science students and researchers through the process of programming using MATLAB. The book explores examples, terms, and programming needs relevant to those in the behavioral sciences and helps readers perform virtually any computational function in solving their research problems. Principles are illustrated with usable code. Each chapter opens with a list of objectives followed by new commands required to accomplish those goals. These objectives also serve as a reference to help readers easily relocate a section of interest. Sample code and output and chapter problems demonstrate how to write a program and explore a model so readers can see the results obtained using different equations and values. A web site provides solutions to selected problems and the book's program code output and examples so readers can manipulate them as needed. The outputs on the website have color, motion, and sound.

Highlights of the new edition include:

•Updated to reflect changes in the most recent version of MATLAB, including special tricks and new functions.

•More information on debugging and common errors and more basic problems in the rudiments of MATLAB to help novice users get up and running more quickly.

•A new chapter on Psychtoolbox, a suite of programs specifically geared to behavioral science research.

•A new chapter on Graphical User Interfaces (GUIs) for user-friendly communication.

•Increased emphasis on pre-allocation of memory, recursion, handles, and matrix algebra operators.

The book opens with an overview of what is to come and tips on how to write clear programs followed by pointers for interacting with MATLAB, including its commands and how to read error messages. The matrices chapter reviews how to store and access data. Chapter 4 examines how to carry out calculations followed by a review of how to perform various actions depending on the conditions. The chapter on input and output demonstrates how to design programs to create dialogs with users (e.g., participants in studies) and read and write data to and from external files. Chapter 7 reviews the data types available in MATLAB. Readers learn how to write a program as a stand-alone module in Chapter 8. In Chapters 9 and 10 readers learn how to create line and bar graphs or reshape images. Readers learn how to create animations and sounds in Chapter 11. The book concludes with tips on how to use MATLAB with applications such as GUIs and Psychtoolbox.

Intended as a primary text for Matlab courses for advanced undergraduate and/or graduate students in experimental and cognitive psychology and/or neuroscience as well as a supplementary text for labs in data (statistical) analysis, research methods, and computational modeling (programming), the book also appeals to individual researchers in these disciplines who wish to get up and running in MATLAB.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist MATLAB for Behavioral Scientists als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu MATLAB for Behavioral Scientists von David A. Rosenbaum, Jonathan Vaughan, Brad Wyble im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Psychology & Experimental Psychology. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Verlag
Routledge
Jahr
2014
ISBN
9781136281075

1.
Introduction

This chapter covers the following topics:

1.1 Getting oriented
1.2 Getting an overview of this book
1.3 Understanding computer architecture
1.4 Programming principles
1.5 Deciding if a program is needed and whether you should write it
1.6 Being as clear as possible about what your program should do
1.7 Working incrementally
1.8 Being open to negative feedback
1.9 Programming with a friend
1.10 Writing concise programs
1.11 Writing clear programs
1.12 Writing correct programs
1.13 Understanding how the chapters of this book are organized
1.14 Using the website associated with this book
1.15 Obtaining and installing MATLAB
1.16 Acknowledging limits

1.1 Getting Oriented

Computers are vital in every branch of science today, and behavioral science is no exception. When behavioral scientists use computers to obtain responses in questionnaires, present visual stimuli, display brain images, generate data graphs, or write manuscripts, their ability to make efficient progress in their research depends largely on their ability to use computers effectively.
Many specialized computer packages let behavioral scientists do their work, and each one takes some time to learn. It is useful to know how to use these specialized packages, but it is also tantalizing to consider the possibility of learning how to program for yourself. The reason is that all specialized computer packages rely on underlying code, and knowing how to generate such code yourself can allow you to be self-sufficient or nearly so in your own research.
Suppose, for example, that you want to develop a mathematical model of some cognitive process. It is convenient to be able to write a program that lets you explore the mathematical model freely, seeing the results obtained with different equations, different parameter values, and so on. Similarly, to analyze data in ways that would be cumbersome with existing spreadsheet applications, it is refreshing to be able to write the analysis program to your own specifications. For example, to view graphs of obtained or theoretical data in a variety of forms, it is useful to be able to generate the graphs quickly and easily, however you please, not just as stipulated by an existing graphics package.
The computer language introduced here, MATLAB, provides you with these capabilities. MATLAB is available from The MathWorks (www.mathworks.com), a company with which we authors have no affiliation. MATLAB has become popular in several branches of engineering and science, including behavioral science. Nonetheless, to the best of our knowledge, no book has appeared about MATLAB that is written specifically with behavioral scientists in mind. Nor for that matter has a book come out for behavioral scientists about any other general-purpose programming language. The need for such a volume motivated the first edition of this book. Its positive reception encouraged us to revise the text and expand the coverage in this second edition.
Will it be worth your time to read this book? Once you have gone through the text and generated your own MATLAB programs based on the material presented here, you should have enough programming skill to do most of what you need to for your own behavioral research needs. Most importantly, a working knowledge of MATLAB will allow you to perform some analyses that would be tedious, difficult, or impossible otherwise. In addition, you will be able to understand and build upon the work of colleagues who use MATLAB in their work.
You will probably find this book most useful if you use it in two stages. In the first, you will want to go through it, or the parts of it most relevant to your needs, in considerable detail, working problems and developing the hands-on skills that will make you a MATLAB user, not just a MATLAB appreciator. In the second stage, you will be able to rely on the book as a reference, turning quickly to those sections that provide examples you can adapt for your own programming needs.
To make the book as useful as possible as a reference source, we have designed it so you can get the examples you need quickly and easily. You can do so by turning to the opening page of any chapter and finding there a list of things you may want to do. Beneath that list is a compendium of associated commands. The text itself provides examples you can adapt for your own purposes. You can copy those examples by hand into your own programs, or, to avoid typographical errors, you can copy and paste them from the website associated with this book (www.routledge.com/9780415535946), where the programs and their outputs are available, along with the solution to selected problems. Finally, the list of commands introduced in each chapter is listed as well in the Commands Index.

1.2 Getting an Overview of This Book

Acquiring a new skill such as computer programming can be daunting, so it helps to have an overview of what you can expect as you proceed. Here, then, is a roadmap of the contents of this book. Besides signposts, we also provide brief explanations of the goals of each chapter.
  1. Introduction. By reading the present chapter, you will learn more than you may already know about how computers work and what computer programming languages do. You will also learn about the ways you should approach computer programming. Finally, by reading this chapter, you will understand how this book is organized. That information can help you use the book efficiently.
  2. Interacting With MATLAB. By delving into the second chapter, you will learn how to activate MATLAB’s windows in order to open, edit, save, and run MATLAB programs.
  3. Matrices. By studying the third chapter, you will learn how MATLAB enables you to store and access data. Briefly, MATLAB lets you store data in matrices consisting of one or more rows and one or more columns. Matrices are so fundamental to MATLAB that the name of the language is actually short for “Matrix Laboratory.” You can think of a two-dimensional matrix (one having both rows and columns) as analogous to the rows and columns in a spreadsheet.
  4. Calculations. Computers are good at calculating. Chapter 4 shows how to get your computer to carry out calculations with MATLAB.
  5. Contingencies. One of the main purposes of a computer program is to perform different actions depending on existing conditions. The logic of a program involves not only calculations but also decision making, such as evaluating variables differently (or not evaluating them at all), depending on their values.
  6. Input-Output. Chapter 6 shows you how to control your computer’s interactions with the external world. By studying Chapter 6, you will be able to design programs that let you create dialogs with users, including participants in behavioral studies, and to read and write data to and from external files.
  7. Data Types. One of the biggest challenges in using computers in research is determining how best to represent the data you are working with. It is important to understand what data types are available in MATLAB so you can choose and manipulate your data types accordingly.
  8. Modules and Functions. Simple programs are usually easy to understand, but when they become more complex it often helps to deal with them in chunks. Some higher level structure is often helpful. Chapter 8 shows you how to write programs that have this property. Those programs often have stand-alone modules and functions. Such modules and functions can be called by a variety of programs. Using modules and functions can help you approach programming from a top-down rather than a bottom-up perspective. Modules and functions can also facilitate the reuse of programs in the future.
  9. Plots. The ability to generate and manipulate complex graphics for the exploration and presentation of data is widely regarded as one of the special strengths of MATLAB. Chapter 9 exposes you to those strengths by showing you how to make line graphs, bar graphs, and other types of graphs that are suitable for professional presentations and publications.
  10. Lines, Shapes, and Images. Here you will learn how to create, import, or reshape lines, shapes, and other images that can either stand alone or be included in graphs. Chapter 10 will also show you how to generate three-dimensional graphs.
  11. Animation and Sound. Chapter 11 builds on the static graphics of the tenth chapter to manipulate figures using simple animation techniques, generate movies, and generate auditory stimuli.
  12. Enhanced User Interaction. When you think of a typical computer application, what comes to mind is how the program interacts with the user, typically through graphics, the keyboard, the mouse, or touchscreen. Chapter 12 introduces you to some of the tools available in MATLAB for user interactions.
  13. Psychtoolbox. For real-time work, there are some features that MATLAB ordinarily lacks that are needed for precise and flexible stimulus presentation and data acquisition. Chapter 13 describes a sophisticated extension to MATLAB, Psychtoolbox, which adds features to facilitate research using MATLAB, especially in vision research. This chapter also touches on related packages of interest to behavioral scientists in related areas.
  14. Debugging. Programs often have bugs because, for better or worse, programming is often a trial-and-error process. While it is hard to know in advance how to address every possible bug, it is possible, based on the authors’ many goofs of their own, to convey advice about debugging techniques which you may find useful. These are offered in Chapter 13 … oops, Chapter 14 (
    ifig0001.webp
    ).
  15. Going On. Chapter 15, the last chapter of the book, provides pointers for going further with MATLAB. This chapter also directs you to other resources you may want to draw on.
A lot of material will be covered in this book. Do you need to go through all of it? If you have no need to play sounds, show animations, or generate three-dimensional graphics, you may safely ignore large parts of Chapters 9 through 13, though leafing through these chapters may help you overcome any prejudices or fears you might have regarding these topics. At the same time, there are chapters you cannot avoid, at least if you don’t want to emerge from this book the way Woody Allen emerged from his speed-reading of Tolstoy’s epic novel, War and Peace. “It was about Russia” was all he could recall.
The truly essential chapters of this book are Chapters 2 through 5. You cannot go on to the later chapters and expect to have control of your programs if you don’t have command of the material in Chapters 2 through 5, and the only way to gain that command is to work your way through the examples and exercises slowly and carefully. We promise that even if you think you understand how things work, the only way to be sure is to try them out and expose yourself to the feedback you will receive.
As you gain expertise, Chapters 6 through 8 will allow you to write more sophisticated code. Chapters 9 through 13 will provide you with specialized tools for your work and enjoyment. And Chapter 14, as already mentioned, will suggest ways to help you debug efficiently.
A word of advice: Don’t hesitate to revisit earlier sections of the book as you move through it. No one remembers perfectly, and no one understands material quite as fully the first time as in revisits. Your understanding of what may seem very obscure the first time through will be enhanced by the top-down knowledge and context you will acquire touring later material.

1.3 Understanding Computer Architecture

As a first step toward learning to program, it can be helpful to know a bit about computer architecture. Knowing about the main components of a computer can help you understand what features of the environment your program must deal with.
All working computers have five basic elements. As shown in Figure 1.3.1, these are (1) input devices (not only the conventional keyboards and mice, but also the microphones, response buttons, and video and voltage recorders that are useful in the laboratory); (2) output devices (screens, printers, loudspeakers, etc.); (3) storage devices (hard disks, thumb drives, DVDs, the “Cloud,” etc.); (4) primary memory; and (5) the central processing unit. The first three components should need no further explanation. The last two components merit more discussion.
Figure 1.3.1
Figure 1.3.1
Primary memory (item 4 on the list) is l...

Inhaltsverzeichnis