Why am I getting "horzcat" error?
Afficher commentaires plus anciens
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
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
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
le 5 Déc 2023
@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')
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
le 5 Déc 2023
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 = [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);
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
le 5 Déc 2023
Saiabhinav
le 5 Déc 2023
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?
Cris LaPierre
le 5 Déc 2023
@Dyuman Joshi, apologies. I've submitted a bug report for that.
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.
Réponse acceptée
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!




