make a Sequence number
1 次查看(过去 30 天)
显示 更早的评论
Layout=[1,1,1;2,2,2;3,2,1;91,3,1;95,4,2;98,4,0.5]; % first column is node, second column is x coordination, third y coordination
A=[1,2;1,3;3,91;91,95;91,98]% edge of graph
I have node 1,2,3,91,95 and 98. I want to change 91,95,98 to 4,5,6.
and also save 91 is 4, 95 is 5 and 98 to 6.
result shloud be
Layout=[1,1,1;2,2,2;3,2,1;4,3,1;5,4,2;6,4,0.5]; % first column is node, second column is x coordination, third y coordination
A=[1,2;1,3;3,4;4,5;4,6]
0 个评论
采纳的回答
Guillaume
2019-4-12
Layout=[1,1,1;2,2,2;3,2,1;91,3,1;95,4,2;98,4,0.5];
A=[1,2;1,3;3,91;91,95;91,98]
searchreplace = [91, 4; 95, 5; 98, 6]; %2 column matrix. First column is value to search, 2nd column is replacement
[toreplace, bywhat] = ismember(Layout(:, 1), searchreplace(:, 1));
Layout(toreplace, 1) = searchreplace(bywhat(toreplace), 2);
[toreplace, bywhat] = ismember(A, searchreplace(:, 1));
A(toreplace) = searchreplace(bywhat(toreplace), 2);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!