Synchronise data starting from a fixed threshold

Hello guys,
I'm trying to figure out how to manipulate a matrix to synchronise data of each column based on a given threshold. Below an example of the matrix (12x4). I need to obtain the same matrix but only with values > 1 for a lenght of 5 points (5x4). Generally my data will alwasy have a threshold > 1 and I will always be able to determine a given number of points such as final length will be the same in the end. Columns however may vary, in this case only 4.
I tried some for loop options discussed in another thread but without finding a real solution. I have got stuck.
0.773487342198182 0.600138756438417 0.772170734960123 0.516639735856335
0.864087340442978 0.615542221162260 0.869415217974424 0.537233561755918
0.991682274100864 0.638389426741996 0.982410980592013 0.615436818611677
1.32088921825082 0.706869092358629 1.09369088583133 0.757585637236141
2.28357938862586 0.907713092310730 1.26556377855575 1.00404112351146
4.90532643030186 1.43660651296947 1.90422770765619 1.55522956023284
11.4072812534284 2.77316107773783 4.37097547909669 3.09343285415927
26.1009031962690 6.15011521861756 12.1192439504818 7.51757113064298
56.2552255198974 14.5139540875845 32.2458223148952 19.2312119978824
112.068671806419 33.8800895937913 76.5865546546643 46.6144406361416
204.680987120115 74.3217216672375 160.666680053232 102.442449362564
341.947876642696 149.265403348143 298.912052552757 201.592183165793

2 件のコメント

jonas
jonas 2018 年 7 月 31 日
I do not understand. Give an example of input and output of a single column.
Giuseppe
Giuseppe 2018 年 7 月 31 日
Input is above in the original message. I would expect this outcome (example first column starting from the first value >1 with length equal 5 points):
1.320889218
2.283579389
4.90532643
11.40728125
26.1009032

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

 採用された回答

jonas
jonas 2018 年 7 月 31 日
編集済み: jonas 2018 年 8 月 1 日

1 投票

With the data given in the comment to this answer, try this script:
A=readtable('data.csv');
A=table2array(A)
A(A<1)=NaN;
A=mat2cell(A,size(A,1),ones(1,size(A,2)))
A=cellfun(@(x)x(~isnan(x)),A,'uniformoutput',false)
A=cellfun(@(x)x(1:5),A,'uniformoutput',false)
out=cell2mat(A)

6 件のコメント

Giuseppe
Giuseppe 2018 年 7 月 31 日
Thanks. Though, they do increase but at some point they will decrease untill they will reach again a value close to zero. Any idea on how to solve that?
Giuseppe
Giuseppe 2018 年 7 月 31 日
Actual file attached. I think 50 points after the threshold (>1) should give the same length for all columns. This to avoid errors (e.g. mismatch, etc.)
jonas
jonas 2018 年 8 月 1 日
updated the solution
Giuseppe
Giuseppe 2018 年 8 月 3 日
Cheers Jonas.
This mainly work but I spot some issues related to my needs. If I do A<1 = NaN I may end up with some of the data lost because the whole signal is prettymuch a parabole, therefore, I will have <1 at the beginning of the signal but also at the end. I would need to tell Matlab that <1 should be NaN only for a given length, the rest should not be replaced. Not sure if it makes sense but if you look at the data.csv file you will see what the signals look like. I have given the example of new length = 5 but in the specific case of data.csv that would be around 50 points.
jonas
jonas 2018 年 8 月 3 日
編集済み: jonas 2018 年 8 月 3 日
Next iteration. I will allow one for-loop this time :)
A=readtable('data.csv');
A=table2array(A);
A=mat2cell(A,size(A,1),ones(1,size(A,2)))
for i=1:length(A)
A{i}(1:find(A{i}>=1,1,'first'))=NaN;
end
A=cellfun(@(x)x(~isnan(x)),A,'uniformoutput',false)
A=cellfun(@(x)x(1:5),A,'uniformoutput',false)
out=cell2mat(A)
The difference here is that the loop only removes data up until the first '1'. This means that you can now end up with values less than one in your output, granted that they appear shortly after the first one.
Giuseppe
Giuseppe 2018 年 8 月 4 日
Cheers jonas. That improved the code.

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2014a

質問済み:

2018 年 7 月 31 日

コメント済み:

2018 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by