Error using horzcat dimensions

6 次查看(过去 30 天)
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
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
Thats fantastic, thanks a lot!
Star Strider
Star Strider 2019-11-8
@Nicky Wiggs — As always my pleasure!
@Stephen — Thanks for your addition.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by