Hi!
I've an array that is A but I'd like to create another array, B, that containes in order the position of this values.
For example: if A is [1000,700,500,350,200,100,50,15], B must be [8,7,6,5,4,3,2,1].
I tried to do:
a = 8; % a is number of values in array
A = [1000,700,500,350,200,100,50,15];
for i = 1:a
B = A(i)
end
but B is not an array. How can I do?

댓글 수: 4

Dennis
Dennis 2018년 5월 7일
편집: Dennis 2018년 5월 7일
So B is just descending from length of A?
B=fliplr([1:length(A)])
You need to change B to B(i) in your code to get a vector. Right now you are overwriting B in every iteration. But then B would have the same values as A.
Stephen23
Stephen23 2018년 5월 7일
편집: Stephen23 2018년 5월 7일
" I'd like to create another array, B, that containes in order the position of this values"
Then use sort:
[~,B] = sort(A)
EDIT: see also earlier question, with an impossibly complex approach to this problem:
sc
sc 2018년 5월 7일
'So B is just descending from length of A?'
No, because for example: if: A = [1000,500,700,350,100,200,50,15]; B must be B = [8,6,7,5,3,4,2,1].
In practice I should associate the values of A to the values of B, but values however may not be descendants.
It's hard to explain: I would like to create the ascending order of A's values, but insert them in order of appearance in B.
Is it possible?
Jan
Jan 2018년 5월 11일
@sc: Please stop closing your question, when they got accepted answers already. After closing the questions are deleted, and this would remove the invested time of the ones, who help you. This is counter-productive in a public forum.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2018년 5월 7일

0 개 추천

Maybe:
B = numel(A):-1:1
if the array A is sorted already. Otehrwise:
[~, B] = sort(A, 'ascend')

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

sc
2018년 5월 7일

댓글:

Jan
2018년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by