I'm having issues with my end output. It seems to be due to the id variable.
This is printed when ran;
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in week5analysis (line 30)
output=[id dacc drt];
function [output]=week5analysis(data)
%input should create a directory of one or more files
files=dir(data);
%index k should correspond to the number of files within the directory
for k=1:size(files,1)
%extracting id and converting to corresponding number
id=(files(k).name(4:size(files(k).name,2)));
%loading the files within the directory
temp=load(files(k).name);
%removes the first 10 practice trails in both conditions
temp([1:10,51:60],:)=[];
%condition 1
c1=temp(temp(:,1)==1,:);
%condition 2
c2=temp(temp(:,1)==2,:);
%displays the percentage of correct answers for condition 1
acc1=sum(c1(:,2)==1)/numel(c1(:,2))*100;
%displays the percentage of correct answers for condition 2
acc2=sum(c2(:,2)==1)/numel(c2(:,2))*100;
%mean of reaction time for correct trails in condition 1
c1m=mean(c1(c1(:,2)==1,3));
%mean of reaction time for correct trails in condition 2
c2m=mean(c2(c2(:,2)==1,3));
%difference between each condition for accuracy
dacc=c1(:,2)-c2(:,2);
%difference between each condition for reaction time
drt=c1(:,3)-c2(:,3);
%saves difference scores alongside id
output=[id dacc drt];
end

 採用された回答

Star Strider
Star Strider 2019 年 11 月 8 日

0 投票

I have no idea what your code does or what the variables are that you want to return.
The easiest approach is to return a cell array instead:
output = {id dacc drt};
Note the curly brackets {} denoting a cell array.
See the documentation on Cell Arrays if you are not familiar with them.

4 件のコメント

Nicky Wiggs
Nicky Wiggs 2019 年 11 月 8 日
Amazing! That works almost perfectly, would it be possible to do it so its in numerical order for the id also?
Stephen23
Stephen23 2019 年 11 月 8 日
"would it be possible to do it so its in numerical order for the id also?"
You could try my FEX submission:
Nicky Wiggs
Nicky Wiggs 2019 年 11 月 8 日
Thats fantastic, thanks a lot!
Star Strider
Star Strider 2019 年 11 月 8 日
@Nicky Wiggs — As always my pleasure!
@Stephen — Thanks for your addition.

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by