I have a table, Table_A, with 500 elements.
I have a vector, x, with number 1:500 in a random order.
I want to rearrange the table based on the values of x. For example, if the first three elements of x are 383, 24, 191, then the 393rd row of Table_A will be moved to row 1, the 24th row will be moved to row 2, the 191st row will be moved to row 3 and so on.
Any help is appreciated.
Thank you.

 채택된 답변

Erik J
Erik J 2020년 12월 11일

0 개 추천

I was able to figure this out.
new_table = zeros(500,8);
new_table = array2table(new_table);
a = randperm(500);
for ii=1:500
row = stim_sheet(a(ii),:);
new_table(ii,:) = row;
end

추가 답변 (1개)

Stephen23
Stephen23 2020년 12월 12일

0 개 추천

The MATLAB approach:
new_table = stim_sheet(a,:)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2020년 12월 11일

답변:

2020년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by