So my code is just a large matrix with 6 columns, but with thousands of rows.
Below is my code, but for some reason the error appears in the Comsnd Window:
"Error using horzcat
Dimensions of arrays being concatenated are not consistent."
All the code below is inputted into the command window
% data = [MATRIX DATA];
%Alpha Waves
time=data(:,1);
alpha=data(:,3);
beta=data(:,4);
delta=data(:,5);
theta=data(:,6);
control=time<=20;
theend=time>40;
experiment=logical(~control - theend);
figure,subplot(3,1,1),plot(time(control),alpha(control))
ylim([-115 115])
title('Alpha Waves')
ylabel('Before Trial')
subplot(3,1,2),plot(time(experiment),alpha(experiment))
ylim([-115 115])
ylabel('Experiment')
subplot(3,1,3),plot(time(theend),alpha(theend))
ylabel('End of Trial')
xlabel('time (s)')
xlim([40 60])
ac = alpha(control);
ae = alpha(experiment);
at = alpha(theend);
[q,w,stats]=anova1(abs([ac(1:end-1) ae at(1:end-59)]),{'Control' 'Experiment' 'The End (Control-Final)'});
figure,multcompare(stats);
I think its due to the last line of code, but it's strange why the error is ocurring because i worked before. I did make some changes and i can't remember as to which my have caused the issue. I am getting a graph of the Electroencephelogram (EEG) Data though.

12 commentaires

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Déc 2023
There mightbbe the dimensions of ac(1:end-1), ae, & at(1:end-59) are not compatible for horizontal concatenation. Check once, more share the complete code and data, so that we can try.
Dyuman Joshi
Dyuman Joshi le 5 Déc 2023
When you use linear indices to access data from arrays, the output is a column vector.
And the number of rows of ac(1:end-1), ae and at(1:end-59) are not the same, thus you get the error for horizontal concatenation.
However, did you mean to use linear indices, or did you want to get the rows or columns according to the indices used?
Saiabhinav
Saiabhinav le 5 Déc 2023
Hi Kalyan I attached the Excel data
@Saiabhinav, I can't seem to access the data in the file.
Most likely, the file does not have read access.
y = detectImportOptions('Sophia_Z_QASP1...ku-Trial1.xls')
Error using detectImportOptions
Unable to open file '/users/mss.system.iJRKAP/Sophia_Z_QASP1...ku-Trial1.xls' as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
Also, I'll reiterate - Did you mean to use linear indices, or did you want to get the rows or columns according to the indices used?
Saiabhinav
Saiabhinav le 5 Déc 2023
I'm not sure what you mean Dyuman
Cris LaPierre
Cris LaPierre le 5 Déc 2023
Modifié(e) : Cris LaPierre le 5 Déc 2023
Your file does appear to be such an old version of Excel, that readtable/readmatrix cannot import it. Here's an updated version with your code.
data = readmatrix('Sophia_Z_QASP1_Project_Sudoku-Trial1.xlsx')
data = 12083×6
0 -1.5259 -0.0965 1.0925 -1.4515 0.1872 0.0050 -1.8433 -0.4028 1.3945 -1.4648 0.3414 0.0100 -2.5208 -0.6122 1.0976 -1.4713 0.4758 0.0150 -2.8809 -0.7112 0.3421 -1.4702 0.5882 0.0200 -3.6804 -0.7154 -0.4777 -1.4612 0.6756 0.0250 -3.6011 -0.6574 -0.9594 -1.4445 0.7342 0.0300 -3.2776 -0.5703 -0.9121 -1.4208 0.7603 0.0350 -2.5208 -0.4749 -0.4108 -1.3912 0.7520 0.0400 -1.6541 -0.3730 0.2798 -1.3570 0.7108 0.0450 -1.2451 -0.2524 0.8307 -1.3188 0.6430
% data = [MATRIX DATA];
%Alpha Waves
time=data(:,1);
alpha=data(:,3);
beta=data(:,4);
delta=data(:,5);
theta=data(:,6);
control=time<=20;
theend=time>40;
experiment=logical(~control - theend);
figure,subplot(3,1,1),plot(time(control),alpha(control))
ylim([-115 115])
title('Alpha Waves')
ylabel('Before Trial')
subplot(3,1,2),plot(time(experiment),alpha(experiment))
ylim([-115 115])
ylabel('Experiment')
subplot(3,1,3),plot(time(theend),alpha(theend))
ylabel('End of Trial')
xlabel('time (s)')
xlim([40 60])
ac = alpha(control);
ae = alpha(experiment);
at = alpha(theend);
[q,w,stats]=anova1(abs([ac(1:end-1) ae at(1:end-59)]),{'Control' 'Experiment' 'The End (Control-Final)'});
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
figure,multcompare(stats);
Dyuman Joshi
Dyuman Joshi le 5 Déc 2023
Modifié(e) : Dyuman Joshi le 5 Déc 2023
@Cris LaPierre, I imported the excel file via 'Link from this thread' option. Answers imported the file with that name, or maybe it condensed the file name, idk for sure.
And that behaviour is consistent with files with large names, but I have only encountered an error with this particular file.
If I find any previous such encounter where a file with long name works and ellipses, I'll link it here.
Saiabhinav
Saiabhinav le 5 Déc 2023
hi chris thanks for the help, but that's not the issue I'm having. the issue I'm having is the last line of code
[q,w,stats]=anova1(abs([ac(1:end-1) ae at(1:end-59)]),{'Control' 'Experiment' 'The End (Control-Final)'});
figure,multcompare(stats);
The error is:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Saiabhinav
Saiabhinav le 5 Déc 2023
Sorry I just saw the rest. Thank you
Image Analyst
Image Analyst le 5 Déc 2023
I'm also having trouble opening it in MATLAB. I can open it in Excel but can't do anything with it. Even when I try to save it as a modern .xlsx file, it won't do it. Can you attach the data in a normal Sophia_Z_QASP1_Project_Sudoku-Trial1.xlsx file?
Dyuman Joshi
Dyuman Joshi le 5 Déc 2023
@Cris LaPierre, you don't need to apologise.
I was just pointing out an inconsistent behaviour. Thank you for submitting the report.

Connectez-vous pour commenter.

 Réponse acceptée

The issue is because the 3 variables you are concatenating in this line of code have different numbers of rows.
[q,w,stats]=anova1(abs([ac(1:end-1) ae at(1:end-59)]),{'Control' 'Experiment' 'The End (Control-Final)'});
  • ac(1:end-1) has 4000 rows
  • ae has 4000 rows
  • at(1:end-59) has 4023 rows (at for this data set is 4082)
The fix, then, is probably to adjust your 3rd variable to at(1:end-82)
data = readmatrix('Sophia_Z_QASP1_Project_Sudoku-Trial1.xlsx')
data = 12083×6
0 -1.5259 -0.0965 1.0925 -1.4515 0.1872 0.0050 -1.8433 -0.4028 1.3945 -1.4648 0.3414 0.0100 -2.5208 -0.6122 1.0976 -1.4713 0.4758 0.0150 -2.8809 -0.7112 0.3421 -1.4702 0.5882 0.0200 -3.6804 -0.7154 -0.4777 -1.4612 0.6756 0.0250 -3.6011 -0.6574 -0.9594 -1.4445 0.7342 0.0300 -3.2776 -0.5703 -0.9121 -1.4208 0.7603 0.0350 -2.5208 -0.4749 -0.4108 -1.3912 0.7520 0.0400 -1.6541 -0.3730 0.2798 -1.3570 0.7108 0.0450 -1.2451 -0.2524 0.8307 -1.3188 0.6430
% data = [MATRIX DATA];
%Alpha Waves
time=data(:,1);
alpha=data(:,3);
beta=data(:,4);
delta=data(:,5);
theta=data(:,6);
control=time<=20;
theend=time>40;
experiment=logical(~control - theend);
figure,subplot(3,1,1),plot(time(control),alpha(control))
ylim([-115 115])
title('Alpha Waves')
ylabel('Before Trial')
subplot(3,1,2),plot(time(experiment),alpha(experiment))
ylim([-115 115])
ylabel('Experiment')
subplot(3,1,3),plot(time(theend),alpha(theend))
ylabel('End of Trial')
xlabel('time (s)')
xlim([40 60])
ac = alpha(control);
ae = alpha(experiment);
at = alpha(theend);
[q,w,stats]=anova1(abs([ac(1:end-1) ae at(1:end-82)]),{'Control' 'Experiment' 'The End (Control-Final)'});
figure,multcompare(stats);

Plus de réponses (0)

Catégories

En savoir plus sur Debugging and Analysis dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by