Error using concatenate when trying to compile individual data (trying to make a histogram)

6 views (last 30 days)
Hi, I'm trying to compile data from 8 subjects into 3 vectors organized by scalae (as relates to a behavioral threshold). I am able to do that, but once I try to concatenate them so as to compile the data, I keep getting this error:
Error using cat Dimensions of matrices being concatenated are not consistent.
Error in histogram_scalae (line 37) allST = cat(2, allST, thresST);
I think it is because not all subjects have electrodes in all scalae (so some will have from 2 and 3, some from 1 and 2) and it doesn't know what to fill it with when this happens. I can't seem to work around it.
Here is my code below:
SUBJECTS = [22 29 38 40 41 42 43 44];
xlsfile = 'C:\Users\Lindsay\Desktop\CTinfo_Oct_2014.xlsx'; %%change to school path
%create empty vectors to be filled in the loop
allthres = [];
allST = [];
allSV = [];
allSM = [];
thresind = [];
%%cycle through all subjects, importing data from Excel
for iSubj = 1:length(SUBJECTS)
%%import relevant data from Excel
qthres = xlsread(xlsfile, iSubj,'J3:J16');
scalae = xlsread(xlsfile, iSubj, 'C3:C16');
%finds scalae
[STi, STj, ST] = (find(scalae == 1 & qthres > 0));
[SMi, SMj,SM] = (find(scalae == 2 & qthres > 0));
[SVi, SVj,SV] = (find(scalae == 3 & qthres > 0));
thresST = qthres(STi);
thresSM = qthres(SMi);
thresSV = qthres(SVi);
%store scalae info for each subject
allST = cat(2, allST, thresST);
allSM = cat(2, allSM, thresSM);
allSV = cat(2, allSV, thresSV);
end
%%plot histogram%%
figure(1);
hist(thresST);
hold on;
hist(thresSM);
hist(thresSV);
THANKS!

Answers (2)

Star Strider
Star Strider on 24 Nov 2014
I am not certain I understand what you’re doing or what the significance of the scalae electrode positions are in your data. Creating empty vectors might not be your best option. Instead, preallocating matrices so that all are equal size might be better. It could also solve your concatenation problem.
  2 Comments
Star Strider
Star Strider on 24 Nov 2014
No worries. I’ll continue my comments here.
I’m having problems understanding your code. If you’re getting electrode position on y rather than your scalae value, how do your electrode positions relate to your scalae values? (Your ‘ST’, ‘SM’, and ‘SV’ variables seem to be separated as ‘scalae’.) What is supposed to be on the x-axis?

Sign in to comment.


Lindsay
Lindsay on 24 Nov 2014
I actually changed the dimensions to '1' instead of 2 and it worked perfectly. Only problem is that now instead of getting 1, 2, and 3, on the y-axis, I'm getting the electrode index value.
As for the significance, my research is in cochlear implants where an electrode array is inserted into the inner ear. "Scalae" are just different compartments the electrode array can end up in, so I want to organize by histogram so I can see the distribution of these scalae placements relative to the thresholds we collected from our subjects.
I hope that helps.
That being said, I'm not sure now how to get my y-axis correct. Also now sure how to get these in different colors.
%%plot histogram%%
figure(1);
hist(allST);
set(get(gca, 'child'), 'FaceColor', 'none', 'EdgeColor', 'k');
get(get(gca,'child'));
hold all;
hist(allSM);
set(get(gca, 'child'), 'FaceColor', 'none', 'EdgeColor', 'g');
get(get(gca,'child'));
hist(allSV);
set(get(gca, 'child'), 'FaceColor', 'none', 'EdgeColor', 'b');
get(get(gca,'child'));
Thanks!

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!