Adding elements to a column corresponding to the indices

조회 수: 2 (최근 30일)
Hari krishnan
Hari krishnan 2018년 9월 7일
I have a matrix called as 'single_matrix_with_time_id', the first column corresponding to 'frame_number', second column corresponding to 'time', third column with 'identity', fourth column with 'error', fifth and sixth column with 'X and Y coordinates' and seventh column with 'Camera_id'.
What i am trying to do is to take the unique elements from the second column (time) and the elements corresponding to the unique elements of time from the 'first and seventh column' and add it to 'first, second and third column of ' a new matrix called 'final_plot_matrix'. I tried to do this in the code shown below, But it is not giving me the expected outcome. Any help will be appreciated. Mat file is attached
final_plot_matrix = nan(length(unique(single_matrix_with_time_id(:,2)))+1,length(final_filtered_ant_id)+3);
final_plot_matrix(1,4:length(final_filtered_ant_id)+3) = final_filtered_ant_id;
final_plot_matrix = repelem(final_plot_matrix,1,2);
final_plot_matrix(:,1) = [];
final_plot_matrix(:,2) = [];
final_plot_matrix(:,3) = [];
final_plot_matrix(2:length(unique(single_matrix_with_time_id(:,2)))+1,3) = unique(single_matrix_with_time_id(:,2));
[C,ia,ic] = unique(single_matrix_with_time_id(:,2));
frame_number = ia(single_matrix_with_time_id(:,1));
Camera_id = ia(single_matrix_with_time_id(:,3))
final_plot_matrix(2:length(unique(single_matrix_with_time_id(:,2)))+1,2) = frame_number
final_plot_matrix(2:length(unique(single_matrix_with_time_id(:,2)))+1,1) = Camera_id

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by