Lindsay - your code after the plotting starts with the following if statement
if ~isrow(peakamp(peakampi))
peakamp(peakampi) = (peakamp(peakampi))';
end
The condition checks to see if the data in peakamp indexed at peakampi is not a row, and then tries to replace the data with the transpose of that data? There will be no change to the vector peakamp - it will still be a column. Is the intent to modify the column vector to a row vector, or is it something else? Why only consider some of the elements in the vector (i.e. those referenced by peakampi) when the next line
allpeakamp = cat(2, allpeakamp, peakamp);
uses all of the peakamp data?
-------------------
Given that
peakamp = xlsread(xlsfile, 1, 'L3:L16');
reads a number of rows from one column of the Excel spreadsheet, it is going to be a column vector of negative and/or positive values. Then
allpeakamp = cat(2, allpeakamp, peakamp);
is going to concatenate along the column dimension of allpeakamp the peakamp column vector. Over time, this becomes a 14x8 matrix.
Now when you do
[findampi, findampj] = find(allpeakamp > 0);
look at the results for findampi and findampj. Both are column vectors, the first corresponding to the row indices (so will be values from 1-14, repeated for each subject that has data greater than zero) and the second corresponding to the column indices (so will be values from 1-8, repeated for each subject that has data greater than zero). Both vectors will be of the same length.
Now when you evaluate
the code is only using the row indices and not using the column indices from findampj and so the result will only ever be repeated values from the first subject. Here is a small example
The first column has odd numbers, the second even. Now we will do something similar
[rowIdcs, colIdcs] = find(A>0)
rowIdcs =
1
2
3
1
2
3
colIdcs =
1
1
1
2
2
2
Clearly, all elements of A are positive, yet when we try
A(rowIdcs)
ans =
1
3
5
1
3
5
we only see the odd numbers from the first column. That is because when accessing a matrix with a single vector, there is an assumption that we are trying to access these elements using the linear index equivalents to the row and column subscripts. So the repetitive nature of peakampi means that we will only ever access elements from the first column of allpeakamp i.e. the first subject.
To get around this, convert the row and column subscripts of peakampi and peakampj respectively to their linear index equivalents using sub2ind as linIdcs = sub2ind(size(allpeakamp),peakampi,peakampj);
allpeakamp(linIdcs)
Try replacing with the above two lines, and see what happens!
Best Answer