1 / 18

Liat Gantz LGantz@uh

My MATLAB Experience (& Tips). Liat Gantz LGantz@uh.edu. How I use MATLAB in my research. Preliminary Experiments Randomly display stimuli (RDSs) at 6 different contrast levels Subject reports “sees” (up button) or “doesn’t see” (down button) Feedback (beep- i.e. “I got your response”)

oriole
Download Presentation

Liat Gantz LGantz@uh

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. My MATLAB Experience (& Tips) Liat Gantz LGantz@uh.edu

  2. How I use MATLAB in my research

  3. Preliminary Experiments Randomly display stimuli (RDSs) at 6 different contrast levels Subject reports “sees” (up button) or “doesn’t see” (down button) Feedback (beep- i.e. “I got your response”) Record % “see” Record # trials each contrast was presented • Analysis Fit Cumulative Gaussian to the % seen as a function of contrast 50% point is taken as the TH • Data Storage Data are written to XL including the initial parameters (subject name, date, RDSs density, contrast levels shown, subject responses, fitted responses, fit parameters…)

  4. Experiment GUI- insert different parameters Display Stimuli (RDSs or lines embedded within RDSs- crossed/uncrossed. Each at a multiple of contrast detection TH), 6 disparities, random order. Stimuli vary in their size, dot density, exposure duration. Feedback for Correct/ Incorrect Responses Record % “Crossed Responses” Record # trials each disparity was presented • Analysis Fit Cumulative Gaussian to the % crossed as a function of disparity Semi interquartile range is taken as the TH • Data Storage Data are written to XL including the initial parameters (subject name, date, RDSs density, contrast levels shown, subject responses, fitted responses, fit parameters…)

  5. General Tips

  6. To comment a section of code out: %{ Blah blah blah Blah blah blah Blah blah blah Blah blah blah %} • Frequent use of keyboard to check every tiny little step makes debugging much easier. • I frequently check when I have issues: http://tech.groups.yahoo.com/group/psychtoolbox/messages/ • Get people’s old codes!!

  7. MATLAB and Excel (XL)

  8. % creates an activex automation server where excel.application is the % program ID exl = actxserver('excel.application'); % excel.application is the program ID of the ActiveX object and % exl is the handle of the control's default interface. exl.Visible = 1; Workbooks = exl.Workbooks; % reference to a single workbook in XL exlWkbk = Workbooks.Add; Sheets = exl.ActiveWorkBook.Sheets; % reference to the sheets in the % workbook sheet1 = get(Sheets, 'Item', 1); invoke(sheet1, 'Activate'); Activesheet = exl.Activesheet; % if you want to write into excel columns you use no separation within % the brackets [] but if you want into diff rows, you use a ; separation within % the brackets { }so ';' symbolizes 'go down to the next row' % These titles will be inserted on the left most column of the XL sheet % A1 to A4 Titles={'X1';'Y1';'X2';'Y2'}; ActivesheetRange = get(Activesheet,'Range','A1’,’A4’); set(ActivesheetRange, 'Value', Titles);

  9. % I want to place the values of array X1 into the column % beneath the title ‘X1 Values’ which is in cell A6: X1 = {1; 2; 3; 4}; Y1 = {1; 2; 3; 4} % The convention is: row, column rngTmp = Activesheet.Range(‘A6’); rngTmp.value = ‘X1 Values:’; % convert the number of elements into a string X1Length = num2str(numel(X1) +6); % concatenate strings X1Location = strcat(‘A’, X1Length); % similarly to working with XL- we first mark the range that % we want to use- % this is the range of cells into which the array X1 will be % pasted. ActivesheetRange = get(Activesheet,'Range',’A7’,X1Location); % then we paste the values set(ActivesheetRange, 'Value', X1);

  10. Useful to refer back to the XL layout from time to time:

  11. % naming the sheet set(Activesheet,'Name','Experiment Data'); % At the same breath as opening the XL % workbook this should % be inserted at the bottom of % the code to prevent memory leakage issues: exlWkbk.SaveAs(FileName); %invoke(Workbook, 'SaveAs', Filename); %same thing exlWkbk.Close; exl.Quit; exl.delete;

  12. Charts = exl.ActiveWorkBook.Charts; Chart = invoke(Charts,'Add'); set(Chart,'ChartType','xlXYScatter'); % scatter graph %set(Chart,'CartType','xlXYScatterLines'); % scatter line graph % for a list of chart types goto the msdn library: % http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.excel.x % lcharttype.aspx % Setting the Data in the Plot invoke(sheet1, 'Activate'); Activesheet = exl.Activesheet; X1Cell = get(Activesheet,'Range','A7','A7'); X1Cell.Activate; exl.Select; R = exl.Selection.Row; C = exl.Selection.Column; %R = 7 C = 1

  13. Chart = invoke(Chart,'Location',2,'Sheet1'); % In excel, when you have a series of graphs, you click on the 'series' tab % and select a range of values of the following format: % x values: =Sheet1!$A$20:$A$23 % Select a series of graphs: Series = invoke(exl.ActiveChart,'SeriesCollection',1); % uncomment this if you have only 1 data set to graph and not two %invoke(Series,'Delete'); % X1 AXIS Series.XValues = ['=' 'Sheet1' '!R' int2str(R) 'C' int2str(C) ':R' (numel(X1)+6) 'C' int2str(C)]; % Y1 AXIS Series.Name = 'Original Data'; Series.Values = ['=' 'Sheet1' '!R' int2str(R) 'C' int2str(C+1) ':R' (numel(Y1)+6) 'C' int2str(C+1)]; % if you want to add another chart on the same graph: %X2 AXIS NewSeries = invoke(exl.ActiveChart.SeriesCollection,'NewSeries'); NewSeries.XValues = ['=' 'Sheet1' '!R' int2str(R) 'C' int2str(C) ':R' num2str(10) 'C' int2str(C)]; %Y2 AXIS NewSeries.Name = 'Fitted Data'; NewSeries.Values = ['=' 'Sheet1' '!R' int2str(R) 'C' int2str(C+2) ':R' num2str(10) 'C' int2str(C+2)];

  14. % naming the chart/ graph set(Chart,'HasTitle',1); set(Chart.ChartTitle,'Caption','Psychometric Function'); % setting chart title properties %exl.ActiveChart.ChartTitle.Font.Bold = 1; %exl.ActiveChart.ChartTitle.Font.Size = 12; % naming the axes titles x = invoke(Chart,'Axes',1); set(x,'HasTitle',1); set(x.AxisTitle,'Caption','Disparity'); y = invoke(Chart,'Axes',2); set(y,'HasTitle',1); set(y.AxisTitle,'Caption','% Near');

  15. MSDN library (source for plot manipulation data) • ApplyCustomType = Applies a standard or custom chart type to a series. • ApplyDataLabels = Applies data labels to a point, a series, or all the series in a chart. • ClearFormats = Clears the formatting of the object. Delete = Deletes the object. Select = Selects the object. • Copy = Copies the object to the Clipboard. Copies a picture of the point or series to the Clipboard. • DataLabels = Returns an object that represents either a single data label (a DataLabel object) or a collection of all the data labels for the series (a DataLabels collection). • ErrorBar = Applies error bars to the series. Object . • Paste = Pastes a picture from the Clipboard as the marker on the selected series. This method can be used on column, bar, line, or radar charts, and it sets the • MarkerStyle property to xlMarkerStylePicture . • Points = Returns an object that represents a single point (a Point object) or a collection of all the points (a Points collection) in the series. Read-only. • Trendlines = Returns an object that represents a single trendline (a Trendline object) or a collection of all the trendlines (a Trendlines collection) for the series.

  16. Good Luck!

More Related