Hi,
I have simplified my 'multiple radar' problem into this: Lets say I have matrix A, consisting of columns 1 (timestamp) and 2 (value). I want obtain matrices that have ascending timestamps and the difference between the values in column 2 of the new vectors must not be greater than 5.
%Input matrix [timestamp values]
A= [0 100;
0 400;
0 500;
1 103;
1 397;
1 502;
2 506;
2 104;
2 399];
%Now magic happens
%Output matrices per radar [timestamp values]
OUT1= [0 100;
1 103;
2 104];
OUT2= [0 400;
1 397;
2 399];
OUT3= [0 500;
1 502;
2 506];
Hopefully somebody can help me out of this misery

 採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 3 月 2 日
編集済み: KALYAN ACHARJYA 2020 年 3 月 2 日

0 投票

for i=1:length(unique(A(:,1)))
mat{i}=A(A(:,1)==i-1,:);
end
result=cell2mat(mat)
out1=reshape(result(1,:),[2,3])' % Use loop for 3 statements
out2=reshape(result(2,:),[2,3])'
out3=reshape(result(3,:),[2,3])'
# This may be possible without loop also, recomended

6 件のコメント

Mike Mierlo van
Mike Mierlo van 2020 年 3 月 2 日
I get the following error:
Error using reshape
To RESHAPE the number of elements must not change.
Error in [file] (line 15)
out1=reshape(result(1,:),[2,3])' % Use loop for 3 statements
What is the fix for this?
Stephen23
Stephen23 2020 年 3 月 2 日
Note: the requirement "..the difference between the values in column 2 of the new vectors must not be greater than 5" is not checked or ensured by this answer.
Mike Mierlo van
Mike Mierlo van 2020 年 3 月 2 日
Indeed.
So I am still in need of a solution for:
  • the 'RESHAPE' error and
  • the requirement that the difference in advancing indexes of column 2 must not be greater than 5.
Thanks in advance!
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 3 月 2 日
I run the code with the "A" example as you provided in the question
A= [0 100;
0 400;
0 500;
1 103;
1 397;
1 502;
2 506;
2 104;
2 399];
for i=1:length(unique(A(:,1)))
mat{i}=A(A(:,1)==i-1,:);
end
result=cell2mat(mat)
out1=reshape(result(1,:),[2,3])' % Use loop for 3 statements
out2=reshape(result(2,:),[2,3])'
out3=reshape(result(3,:),[2,3])'
Command Window
out1 =
0 100
1 103
2 506
out2 =
0 400
1 397
2 104
out3 =
0 500
1 502
2 399
Please do minor change as per new test data requirements.
Mike Mierlo van
Mike Mierlo van 2020 年 3 月 2 日
Thank you! Now I get the same output. But the output matrices do still not meet the requirement:
  • the difference in advancing indexes of column 2 must not be greater than 5.
Any solution for this part?
Mike Mierlo van
Mike Mierlo van 2020 年 3 月 2 日
Found it myself. result=sort(result) will do the job.
Thanks for the help!!!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by