looping with certain condition

5 views (last 30 days)
aqef alif
aqef alif on 26 Mar 2017
Commented: Jan on 11 Apr 2017
Hi, Supposed I have two matrices A and B. A = size 443823 x 1 and B = size 870 x1
Sample data of Matrix A = A =[1 1 1 (n of times)… 2 2 2(m of times) 3 3 3 (p of times) Until the end.
And sample data in Matrix B = B = [180 182 185 189 150 ..... Till the end].
From above matrix, I would like to assign value from B depends on A in new Matrix C, result as follow- c =[180 180 180 (n times) 182 182 (m times) 185 185 (p times) 189 189 189 189 (... times]
can any one help this.
tq. aqef

Accepted Answer

Jan
Jan on 26 Mar 2017
C = B(A)
  6 Comments
aqef alif
aqef alif on 11 Apr 2017
Edited: aqef alif on 11 Apr 2017
[~,~,Ai] = unique(A);
C=B(Ai);
i tried the above and its work. thank you
Jan
Jan on 11 Apr 2017
I cannot know this. You have to find out what you want to get if the index is larger than teh array: An error message, NaN values, no values by cropping the index vector. I cannot decide this, because I do not know the purpose of the code.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!