Download presentation
Presentation is loading. Please wait.
1
Introduction To Matlab Class 7
Instructors: Hristiyan (Chris) Kourtev and Xiaotao Su, PhD
2
cell arrays ‘cat’ 3 ‘zebra’ ‘dog’ 5 9 10 3 9 5
cell arrays are a different data type they are like a matrix where each element is any other data type example_cell_array = {‘cat’, 3, [5, 9]; ‘zebra’, [10, 3; 9, 5], ‘dog’}; ‘cat’ 3 ‘zebra’ ‘dog’ 5 9 10 3 9 5
3
‘cat’ 3 ‘zebra’ ‘dog’ 5 9 10 3 9 5 a = example_cell_array{2, 3}
example_cell_array{2, 1} = a example_cell_array{2, 2}(2, 1)
4
cell2csv Works just like csvwrite
Will only work with “simple” cell arrays no numeric vectors or matrices data = {‘trial number’, ‘time’, ‘color’, ‘response’; , 5.99, ‘blue’, 3; , 4, ‘green’, 2; 3, 55, ‘yellow’, 2} cell2csv(‘somefile.csv’, data); !Note: cell2csv is not a built in Matlab function. Download it here:
5
important note to add one data element to a cell array
data{5, 3} = 'yellow’ curly braces To add one row of data data(5, :) = {4, 2.93, ‘yellow’, 4} parenthesis data(trial+1, :) = {trial, time, color, response}
6
response = input('What is it?');
stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ', ... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response, ... random_num, is_correct ]; %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); %data_storage csvwrite([subject_name, '.csv'], … guessing_game_data);
7
response = input('What is it?');
stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ', ... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response, ... random_num, is_correct ]; %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); %set up labels guessing_game_data = {‘trial’, ‘response time’, … ‘response’, ‘random_num’, ‘is_correct?’} %record data guessing_game_data(t+1, :) = … {t, response_time, response, random_num, is_correct} %data_storage csvwrite([subject_name, '.csv'], … guessing_game_data); cell2csv
8
Task - color differentiation (part 1)
Take subject name screen_setup trial loop (start with 5) color = [rand*255, rand*255, rand*255] put circles 1-4 on the screen one of the four circles will be slightly off (start with +/-50), color from the others on one of the three color dimensions (randomly chose dimension); careful that your deviation doesn’t go >255 or <0 The subject will click on the circle they feel is different record data (whatever would be useful) if the subject was right in the last loop, the amount the color is off is cut in half, otherwise, increase by half save trial data to csv tip: make a function to determine if the cursor is in a shape function is_in = in_shape(vect, mouse_x, mouse_y)
9
Task - color differentiation (part 2)
Further additions: allow the subject to press to select a circle (using KbCheck) put numbers in the circles Hint: You need to use the following commands: Screen('TextFont', window, fontName*); Screen('TextSize', window, fontSize**); Screen('DrawText', window, textString, x, y, textColor); *fontName can be “Arial”, “Verdana” or other *fontSize can be any number. Start with around 20 and adjust as needed
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.