Removing specific elements from vector

4 ビュー (過去 30 日間)
Miroslav Mitev
Miroslav Mitev 2017 年 11 月 20 日
コメント済み: Miroslav Mitev 2017 年 11 月 20 日
I have an exponentially distributed vector "F" with "M" values. I need to remove "K" amount of values from "F" starting from the smallest values and I also need the vectors "a" and "a_d" that gives the values of "F" and "F_d" in descending order, respectively.
Everything works fine with my code, but I want "F_d" to be vector with "N" values, instead it gives me "M" values and on the "K" positions that I want to remove it puts Zeros. I know I can just remove the Zeros, but how can I make it work properly?
M=32;
K=1;
N=M-K;
F=exprnd(1,1,M);
[a, index] = sort(F,'descend');
a_d=a(1:end-K);
F_d(index(1:N))=a_d;

採用された回答

KL
KL 2017 年 11 月 20 日
編集済み: KL 2017 年 11 月 20 日
Your question is not very clear. First you're defining, M,K,N and F,
M=32;
K=1;
N=M-K;
F=exprnd(1,1,M);
Now you want to remove K elements from F starting smallest. But what is F_d? is it the sorted F in descending order? If so,
[F_d, index] = sort(F,'descend');
If you want to remove K elements from F, but the smallest ones, then,
F = F_d(index(1:N));
Now if you also want to remove K elements,
F_d = F_d(1:N);
now what is a and a_d? The values of F and F_d are stored in F and F_d.
  1 件のコメント
Miroslav Mitev
Miroslav Mitev 2017 年 11 月 20 日
It is not what I was looking for. Anyway, thank you for your effort, I fixed the problem by myself. I accept your answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by