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

3 ビュー (過去 30 日間)
Lindsay
Lindsay 2014 年 11 月 24 日
コメント済み: Chad Greene 2014 年 11 月 24 日
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!

回答 (2 件)

Star Strider
Star Strider 2014 年 11 月 24 日
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 件のコメント
Lindsay
Lindsay 2014 年 11 月 24 日
Oops, meant to reply to you. Please see my post below.
Star Strider
Star Strider 2014 年 11 月 24 日
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?

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


Lindsay
Lindsay 2014 年 11 月 24 日
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!
  1 件のコメント
Chad Greene
Chad Greene 2014 年 11 月 24 日
Somewhat of an aside, but histf is a slightly less clunky way to format histograms.

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by