Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matlab Class 6 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev.

Similar presentations


Presentation on theme: "Matlab Class 6 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev."— Presentation transcript:

1 Matlab Class 6 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev

2 RuCCS Managing data To manage basic numerical data we use matrices our_data = [1, 4, 10.59, 12; 2, 9, 18.76, 5; 3, 7, 1.13, 2]; Trial 1 Trial 2 Trial 3 Response 1 Response 2 (perhaps the response time) Response 3 Trial Number

3 RuCCS our_data = [1, 4, 10.59, 12; 2, 9, 18.76, 5; 3, 7, 1.13, 2]; To set the 4th row (4th trial) data: our_data(4, :) = [4, 7, 2.93, 3] –or we could our_data(5, 1) = 5; our_data(5, 2) = 1; our_data(5, 3) = 2.10; our_data(5, 4) = 9; To get this 4th row data –trial_data = our_data(4, :) : gets or sets all elements from row or column

4 RuCCS %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)]); 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 ]; end

5 RuCCS %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)]); 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 ]; end Task 1: Write this section of the program Hint: input without ‘s’ is a good way To get numeric responses from The subject

6 RuCCS %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)]); 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 ]; end

7 RuCCS %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)]); 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 ]; end

8 RuCCS CSV format Stands for “Comma separated value” It is a simple text file for data storage Each data item is delimited (separated) by a comma Each data row is delimited by a return character

9 RuCCS Notepad example Start->run notepad 1, 4, 9.3 1, 9, 100 4, 0, 12 Save as test.csv Double click -> opens in excel

10 RuCCS csvwrite saves a 2d matrix as a csv file csvwrite(FILENAME, MATRIX_VAR) my_matrix = [3, 5; 1, 2]; csvwrite(‘my_data.csv’, my_matrix);

11 RuCCS %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)]); 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 ]; end %data_storage csvwrite([subject_name, '.csv'], … guessing_game_data);

12 RuCCS csvread clear all; my_matrix = csvread(‘my_data.csv’); can be used to load parameters at the beginning of a program can be used to load data to analyze through matlab

13 RuCCS cell arrays this_is_a_matrix_and_a_vector = [5, 3, 9, 3] and_so_is_this = [‘hello’]; which_is_the_same_as = [‘h’, ‘e’, ‘l’, ‘l’, ‘o’];

14 RuCCS cell arrays cell array provides a storage mechanism for dissimilar kinds of data 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’ 59 103 95

15 RuCCS a = example_cell_array{2, 3} example_cell_array{2, 1} = a example_cell_array{2, 2}(2, 1) ‘cat’3 ‘zebra’‘dog’ 59 103 95

16 RuCCS Next class saving cell arrays as csv in class project


Download ppt "Matlab Class 6 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev."

Similar presentations


Ads by Google