I am trying to find the difference in two columns on my csv file to plot them and my current code isnt working.
I have a code that intakes all of my participants per there csv file and outputs there data by the objects they have seen however I cannot code the difference between the known midpoint of the object versus what they have answered. Am I overlooking something? I did change some of the info to keep more discreet sorry. Thank you to anyone who helps!
% Select CSV file and read data
[filename, path] = uigetfile(‘*.csv’, ‘Select The CSV to View Subject Data’);
myCSV = readtable(fullfile(path, filename));
% Define the column indices for KeyPressCount and ResponseTime
Midpoint = 60;
Final_Answered_Midpoint = 76;
%Assigning condition names by category {row, column}
ConditionNames{1,1} = ‘1’;
ConditionNames{2,1} = ‘2’;
ConditionNames{3,1} = ‘3’;
ConditionNames{4,1} = ‘4’;
ConditionNames{5,1} = ‘5’;
ConditionNames{6,1} = ‘6’;
ConditionNames{7,1} = ‘7’;
ConditionNames{8,1} = ‘8’;
ConditionNames{9,1} = ‘9’;
ConditionNames{10,1} = ’10’;
ConditionNames{11,1} = ’11’;
ConditionNames{12,1} = ’12’;
NbrCond = size(ConditionNames,1);
%Difference between midpoint and final slider position that was answered
difference = myCSV{:,76} – myCSV{:,60};
%Creating a loop that through each of the Categories (ConditionNames) in column 1 of myCSV and
%reports the row indices every time each category is found
for condi = 1:NbrCond
ConditionIndex(condi).RowIndices = [];
Indices = strfind(table2array(myCSV(:,1)), ConditionNames{condi,1}); %Strfind the current (condi) condition in the array
counter = 0;
for j = 1:size(Indices,1)
if ~isempty(Indices{j,1})
counter = counter + 1;
ConditionIndex(condi).RowIndices(counter) = j;
end
end
end
%Loops over each category (ConditionNames) in CSV to find data (ex:
%KeyPressCount) and stores it in AllData
for condi = 1:NbrCond
ConditionInstances = size(ConditionIndex(condi).RowIndices,2);
counter = 0;
for Condi_instance_i = 1:ConditionInstances
CurrentRowIndex = ConditionIndex(condi).RowIndices(Condi_instance_i);
counter = counter + 1;
%AllData(condi).Category(counter,1) = final_slider_position_pix-Midpoint;
AllData(condi).Category(counter,1) = myCSV{CurrentRowIndex, difference};
end
end
% Calculating Averages, Standard Deviations, and Standard Errors and
% storing them in AllData by Category (Row)
for condi = 1:NbrCond
AllData(condi).Mean = mean(AllData(condi).Category);
AllData(condi).StdDev = std(AllData(condi).Category);
AllData(condi).StdErr = AllData(condi).StdDev / sqrt(size(AllData(condi).Category, 1));
end
CategoryAvgs = cellfun(@(x) mean(x), {AllData(:).Category});
CategoryStdDevs = cellfun(@(x) std(x), {AllData(:).Category});
CategoryStdErrs = CategoryStdDevs ./ sqrt(cellfun(@numel, {AllData(:).Category}));
%Creating variable to store all of the means and standarderrors for
%plotting purposes
Means = [AllData.Mean];
StdErrs = [AllData.StdErr];
%Creating a figure to summarize results
figure;
bar([AllData.Mean]);
hold on;
errorbar(1:NbrCond, CategoryAvgs, CategoryStdErrs, ‘.k’);
ylim([-10 25])
xlabel(‘Tools’);
ylabel(‘Difference’);
% Set x-axis labels (goes in order of AllData.Mean)
xticklabels({‘1’, ‘2’, ‘3’, ‘4’, …
‘5’, ‘6’, ‘7’, ‘8’, …
‘9’, ’10’, ’11’, ’12’});
xtickangle(45)
hold off;I have a code that intakes all of my participants per there csv file and outputs there data by the objects they have seen however I cannot code the difference between the known midpoint of the object versus what they have answered. Am I overlooking something? I did change some of the info to keep more discreet sorry. Thank you to anyone who helps!
% Select CSV file and read data
[filename, path] = uigetfile(‘*.csv’, ‘Select The CSV to View Subject Data’);
myCSV = readtable(fullfile(path, filename));
% Define the column indices for KeyPressCount and ResponseTime
Midpoint = 60;
Final_Answered_Midpoint = 76;
%Assigning condition names by category {row, column}
ConditionNames{1,1} = ‘1’;
ConditionNames{2,1} = ‘2’;
ConditionNames{3,1} = ‘3’;
ConditionNames{4,1} = ‘4’;
ConditionNames{5,1} = ‘5’;
ConditionNames{6,1} = ‘6’;
ConditionNames{7,1} = ‘7’;
ConditionNames{8,1} = ‘8’;
ConditionNames{9,1} = ‘9’;
ConditionNames{10,1} = ’10’;
ConditionNames{11,1} = ’11’;
ConditionNames{12,1} = ’12’;
NbrCond = size(ConditionNames,1);
%Difference between midpoint and final slider position that was answered
difference = myCSV{:,76} – myCSV{:,60};
%Creating a loop that through each of the Categories (ConditionNames) in column 1 of myCSV and
%reports the row indices every time each category is found
for condi = 1:NbrCond
ConditionIndex(condi).RowIndices = [];
Indices = strfind(table2array(myCSV(:,1)), ConditionNames{condi,1}); %Strfind the current (condi) condition in the array
counter = 0;
for j = 1:size(Indices,1)
if ~isempty(Indices{j,1})
counter = counter + 1;
ConditionIndex(condi).RowIndices(counter) = j;
end
end
end
%Loops over each category (ConditionNames) in CSV to find data (ex:
%KeyPressCount) and stores it in AllData
for condi = 1:NbrCond
ConditionInstances = size(ConditionIndex(condi).RowIndices,2);
counter = 0;
for Condi_instance_i = 1:ConditionInstances
CurrentRowIndex = ConditionIndex(condi).RowIndices(Condi_instance_i);
counter = counter + 1;
%AllData(condi).Category(counter,1) = final_slider_position_pix-Midpoint;
AllData(condi).Category(counter,1) = myCSV{CurrentRowIndex, difference};
end
end
% Calculating Averages, Standard Deviations, and Standard Errors and
% storing them in AllData by Category (Row)
for condi = 1:NbrCond
AllData(condi).Mean = mean(AllData(condi).Category);
AllData(condi).StdDev = std(AllData(condi).Category);
AllData(condi).StdErr = AllData(condi).StdDev / sqrt(size(AllData(condi).Category, 1));
end
CategoryAvgs = cellfun(@(x) mean(x), {AllData(:).Category});
CategoryStdDevs = cellfun(@(x) std(x), {AllData(:).Category});
CategoryStdErrs = CategoryStdDevs ./ sqrt(cellfun(@numel, {AllData(:).Category}));
%Creating variable to store all of the means and standarderrors for
%plotting purposes
Means = [AllData.Mean];
StdErrs = [AllData.StdErr];
%Creating a figure to summarize results
figure;
bar([AllData.Mean]);
hold on;
errorbar(1:NbrCond, CategoryAvgs, CategoryStdErrs, ‘.k’);
ylim([-10 25])
xlabel(‘Tools’);
ylabel(‘Difference’);
% Set x-axis labels (goes in order of AllData.Mean)
xticklabels({‘1’, ‘2’, ‘3’, ‘4’, …
‘5’, ‘6’, ‘7’, ‘8’, …
‘9’, ’10’, ’11’, ’12’});
xtickangle(45)
hold off; I have a code that intakes all of my participants per there csv file and outputs there data by the objects they have seen however I cannot code the difference between the known midpoint of the object versus what they have answered. Am I overlooking something? I did change some of the info to keep more discreet sorry. Thank you to anyone who helps!
% Select CSV file and read data
[filename, path] = uigetfile(‘*.csv’, ‘Select The CSV to View Subject Data’);
myCSV = readtable(fullfile(path, filename));
% Define the column indices for KeyPressCount and ResponseTime
Midpoint = 60;
Final_Answered_Midpoint = 76;
%Assigning condition names by category {row, column}
ConditionNames{1,1} = ‘1’;
ConditionNames{2,1} = ‘2’;
ConditionNames{3,1} = ‘3’;
ConditionNames{4,1} = ‘4’;
ConditionNames{5,1} = ‘5’;
ConditionNames{6,1} = ‘6’;
ConditionNames{7,1} = ‘7’;
ConditionNames{8,1} = ‘8’;
ConditionNames{9,1} = ‘9’;
ConditionNames{10,1} = ’10’;
ConditionNames{11,1} = ’11’;
ConditionNames{12,1} = ’12’;
NbrCond = size(ConditionNames,1);
%Difference between midpoint and final slider position that was answered
difference = myCSV{:,76} – myCSV{:,60};
%Creating a loop that through each of the Categories (ConditionNames) in column 1 of myCSV and
%reports the row indices every time each category is found
for condi = 1:NbrCond
ConditionIndex(condi).RowIndices = [];
Indices = strfind(table2array(myCSV(:,1)), ConditionNames{condi,1}); %Strfind the current (condi) condition in the array
counter = 0;
for j = 1:size(Indices,1)
if ~isempty(Indices{j,1})
counter = counter + 1;
ConditionIndex(condi).RowIndices(counter) = j;
end
end
end
%Loops over each category (ConditionNames) in CSV to find data (ex:
%KeyPressCount) and stores it in AllData
for condi = 1:NbrCond
ConditionInstances = size(ConditionIndex(condi).RowIndices,2);
counter = 0;
for Condi_instance_i = 1:ConditionInstances
CurrentRowIndex = ConditionIndex(condi).RowIndices(Condi_instance_i);
counter = counter + 1;
%AllData(condi).Category(counter,1) = final_slider_position_pix-Midpoint;
AllData(condi).Category(counter,1) = myCSV{CurrentRowIndex, difference};
end
end
% Calculating Averages, Standard Deviations, and Standard Errors and
% storing them in AllData by Category (Row)
for condi = 1:NbrCond
AllData(condi).Mean = mean(AllData(condi).Category);
AllData(condi).StdDev = std(AllData(condi).Category);
AllData(condi).StdErr = AllData(condi).StdDev / sqrt(size(AllData(condi).Category, 1));
end
CategoryAvgs = cellfun(@(x) mean(x), {AllData(:).Category});
CategoryStdDevs = cellfun(@(x) std(x), {AllData(:).Category});
CategoryStdErrs = CategoryStdDevs ./ sqrt(cellfun(@numel, {AllData(:).Category}));
%Creating variable to store all of the means and standarderrors for
%plotting purposes
Means = [AllData.Mean];
StdErrs = [AllData.StdErr];
%Creating a figure to summarize results
figure;
bar([AllData.Mean]);
hold on;
errorbar(1:NbrCond, CategoryAvgs, CategoryStdErrs, ‘.k’);
ylim([-10 25])
xlabel(‘Tools’);
ylabel(‘Difference’);
% Set x-axis labels (goes in order of AllData.Mean)
xticklabels({‘1’, ‘2’, ‘3’, ‘4’, …
‘5’, ‘6’, ‘7’, ‘8’, …
‘9’, ’10’, ’11’, ’12’});
xtickangle(45)
hold off; difference MATLAB Answers — New Questions