Extract time of stimulation using bwlabel function
古いコメントを表示
Hi,
Consider the following matrix:
if true
0 0
0 0
0 0
0 1
1 1
1 1
1 0
1 0
0 2
0 2
0 2
2 0
2 0
2 0
0 3
0 3
0 3
3 0
3 0
3 0
0 4
0 4
0 4
4 0
4 0
4 0
0 0
0 5
0 5
5 5
5 0
5 0
0 0
0 0
0 0
0 0
0 0
6 6
6 6
6 6
6 6
end
I would like to have a code that would allow me to determine the rows for the first occurrence of 1,2,3,4,5 and 6 for the first and the second column. As it follows:
if true
5 4
12 9
18 15
24 21
30 28
38 38
end
Which are respectively the values of the rows from the values 1-6 for each individual column.
To make the code more versatile, it would be perfect to have the code in a lop for "n" columns because the input matrix (cutoff) can have different columns accordingly to the analysis performed.
Thank you in advance.
Best regards,
PS: thank you Guillaume for the help editing the post!
3 件のコメント
Can it be assumed that all the 2s, 3s, etc. are together in one run, as in your example matrix? Can it also be assumed that the runs are in order, 2s before 3s, before 4s, etc, as in your example matrix?
If so, then the problem reduces to finding the start of each continuous run in each column, which my answer already does.
Tiago Campelo
2018 年 8 月 10 日
Guillaume
2018 年 8 月 10 日
Oh yes, it was only looking for a diff of 1. Looking for any positive diff fixes it. See edit.
回答 (2 件)
[startrow, whichcolumn] = find(diff([zeros(1, size(m, 2)); m]) > 0)
If it's absolutely guaranteed that there will be the same number of runs in each column, you can transform the above into your output matrix:
output = reshape(startrow, [], size(m, 2))
2 件のコメント
Tiago Campelo
2018 年 8 月 10 日
This is completely different from what you originally asked. Rather than giving us half baked example (in this latest example each value appears only once in each column, is that really the case?), can you attach a sample of real data and the desired output.
Also, please use the {}Code button to format your posts (as I did for you for your question).
Image Analyst
2018 年 8 月 10 日
Is this what you want:
m = [...
0 0
1 0
1 0
0 1
0 1
2 0
2 0]
% Analyze column 1
props1 = regionprops(m(:, 1), 'PixelIdxList');
allIndexes = [props1.PixelIdxList];
firstTimes1 = allIndexes(1,:) % Get line (row) numbers of the starting elements.
% Analyze column 2
props2 = regionprops(m(:, 2), 'PixelIdxList');
allIndexes = [props2.PixelIdxList];
firstTimes2 = allIndexes(1,:) % Get line (row) numbers of the starting elements.
It basically gives the first element of each labeled region for each column, one column at a time.
m =
0 0
1 0
1 0
0 1
0 1
2 0
2 0
firstTimes1 =
2 6
firstTimes2 =
4
2 件のコメント
Tiago Campelo
2018 年 8 月 10 日
Image Analyst
2018 年 8 月 10 日
How did you change it? Because it works as it, with the matrix you provided.
カテゴリ
ヘルプ センター および File Exchange で Electrophysiology についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!