How can I store y-values in one place after drawing data from different Excel sheets?
Show older comments
I am somewhat new to Matlab and often know what I need to do but am unable to execute it. Anyway, I am pulling amplitude data from various Excel sheets and plotting it on 1 figure (so, group data). The issue is that I need to take this data I've congregated and generate a best fit line for the whole group. I imagine I need all x and y values from every subject in order to do so. However, I can't figure out how to build a new vector with all of the imported data. See code below:
for isubj = 1:length(SUBJECTS)
groupamp = zeros(1, 128);
if isubj == 1
qthres = xlsread(xlsfile, 1,'J3:J16');
peakamp = xlsread(xlsfile, 1, 'L3:L16');
scalae = xlsread(xlsfile, 1, 'C3:C16'); % can only use elecs 2-15 here because of qthres!
[STi, STj, ST] = (find(scalae == 1 & peakamp > 0));
[SMi, SMj,SM] = (find(scalae == 2 & peakamp > 0));
[SVi, SVj,SV] = (find(scalae == 3 & peakamp > 0));
[peakampi, peakampj] = find(peakamp > 0);
elseif isubj == 2
qthres = xlsread(xlsfile, 2,'J3:J16');
peakamp = xlsread(xlsfile, 2, 'L3:L16');
scalae = xlsread(xlsfile, 2, 'C3:C16');
[STi, STj, ST] = (find(scalae == 1 & peakamp > 0));
[SMi, SMj,SM] = (find(scalae == 2 & peakamp > 0));
[SVi, SVj,SV] = (find(scalae == 3 & peakamp > 0));
[peakampi, peakampj] = find(peakamp > 0);
..this goes to isubj = 8 and then...
plot(qthres(STi),peakamp(STi), 'ko', 'LineWidth', 1.5);
hold on;
plot(qthres(SMi),peakamp(SMi), 'gd', 'LineWidth', 1.5);
hold on;
plot(qthres(SVi),peakamp(SVi), 'b^', 'LineWidth', 1.5);
hold on;
groupamp(1, peakampi) = [peakamp(peakampi)'];
end
xx = 30:5:60; fit = polyfit(qthres(peakampi),peakamp(peakampi),1); plot(xx, fit(1)*xx+fit(2),'k-', 'LineWidth', 2);
Obviously the polyfit is incorrect here. I just hard-coded the preallocation with the maximum possible value (in this case, 8 subjects by 16 possible amplitudes).
Thanks for helping a beginner!
Accepted Answer
More Answers (0)
Categories
Find more on Correlation Models 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!