Synchronise data starting from a fixed threshold
4 次查看(过去 30 天)
显示 更早的评论
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
2018-7-31
编辑:jonas
2018-8-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 个评论
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!