How to perform operations on time matrices

3 views (last 30 days)
Ok so my problem stems from the analysis of measurements taken from images.
I have an excel sheet where I have a table of measurements where each column is a different cell (replicate) and the rows are the different time points in which the measurements were taken.
I now want to polish the data, exclude replicates (columns) when necessary and do multiple different operations with the values: i.e. calculating the mean value at time 1 between all of the columns and subtracting that to every element of the matrix; translate the column values to the top in order for them to start with the first positive number and eliminating any negative number after that by 'pushing together' the values below.
I.e. my matrix would be a = 0 2.3450 3.4570
1.0000 3.4670 4.8750
2.0000 4.6350 5.8350
I would first like to calculate the mean of the values of the first row (2.345 and 3.457) = 2.901
Then substract that to every value of the matrix i.e. a = 0 -0.5560 0.5560
1.0000 0.5660 1.9740
2.0000 1.7340 2.9340
Then I eliminate any negative value by filling the gaps with the lower values on the column i.e. a= 0 0.5660 0.5560
1.0000 1.7340 1.9740
2.0000 0 2.9340
If the matrix instead was c = 0 0.5660 0.5560
1.0000 1.7340 -1.6460
2.0000 0 2.9340
I would want the matrix to become c = 0 0.5660 0.5560
1.0000 1.7340 2.9340
2.0000 0 0
Is there any function or operation that could help me do those kind of modifications to the matrix?
Thank you!

Accepted Answer

Stephen23
Stephen23 on 25 Oct 2021
a = [0,2.3450,3.4570;1,3.4670,4.8750;2,4.6350,5.8350]
a = 3×3
0 2.3450 3.4570 1.0000 3.4670 4.8750 2.0000 4.6350 5.8350
m = a(:,2:end)-mean(a(1,2:end));
[~,x] = sort(m<0,1);
for k = 1:size(m,2)
m(:,k) = m(x(:,k),k);
end
a(:,2:end) = max(0,m)
a = 3×3
0 0.5660 0.5560 1.0000 1.7340 1.9740 2.0000 0 2.9340
  4 Comments
LORENZO DAVIDE DODI
LORENZO DAVIDE DODI on 7 Nov 2021
Ok perfect that makes a lot of sense.
I will try to explain myself a bit better:
In this case the criteria for the first value is for it to be non negative: this is achievable by sorting down the negative values. If I wanted to achieve this without considering any negative values further along in the column and therefore leaving any negative values unscathed how could the code be modified.
Another exaple is to have another criteria for the first value: instead of the non-negativity it being a set amount less then the next value in the column: here an example
a=[2,3,2;2.5,3.8,1.8;5,3,2;6,8,2.4;7,10,7;8,11,9]
a =
2.0000 3.0000 2.0000
2.5000 3.8000 1.8000
5.0000 3.0000 2.0000
6.0000 8.0000 2.4000
7.0000 10.0000 7.0000
8.0000 11.0000 9.0000
If the criteria for example for the first 'acceptable' element of the column was the one which had a higher delta then i.e. 2 from the previous one, and therefore something which would return something like this:
a =
2.5000 3.0000 2.4000
5.0000 8.0000 7.0000
6.0000 10.0000 9.0000
7.0000 11.0000 0
8.0000 0 0
0 0 0
Would this be possible to tweak into the existing code or would I need something completely different?
Thank you very much in advance
Stephen23
Stephen23 on 8 Nov 2021
"Would this be possible to tweak into the existing code"
You will need to generate a suitable matrix (it does not have to be a logical matrix) which somehow encodes the "criteria" that you want to sort based on (this itself might require a loop), and then SORT that matrix. Most likely the FOR-loop can stay much the same.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!