Howto replace Element with Element from another Vector at the 1st Element's Position
이전 댓글 표시
Let's say I have a Vector with 100 integer Element between 1 & 100 in no particular Order.
A = [1:100];
A = (randperm (length(A)));
my 2nd Vector can be of any length and contains Integer Elements of any size. Let's Make it:
B = randi([1 200],1,250);
e.g. 250 Elements between 1 & 200 in no particular Order.
Elements of a Size beyond the Dimensions of Vector A don't interest me, so
B (B > 100) = NaN;
Here's what I wanna do:
To Replace all Integer Values in Vector B with the Value in Vector A at that Number's Position.
So let's say the First Element of B is 45. I want to replace it with the 45th Element in Vector A.
If the 2nd Element in B is 89, I want it replaced with the 89th Element in Vector A.
etc.
The NaNs just stay NaNs.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!