delete and insert entries in a vector

Hi All,
I have the following vector
c = [1 1 3 4 5 6 7 8 11 10]
I have to delete entries in position 2 and 9
c_idx = 1:length(c)
c = c(c_idx(c_idx ~=2 & c_idx~=9))
gives,
c_tilda = [ 1 3 4 5 6 7 8 10]
Using c_tilda, I perform a matrix operation
x = A*c_tilda
say, the resulting x is
x = [0.1 0.3 0.4 0.05 0.6 0.7 0.8 0.1]
Now, I'd like to insert values in position 2 and 9 of c in x .
Expected x = [0.1 1 0.3 0.4 0.05 0.6 0.7 0.8 11 0.1]
Could someone suggest how this can be done?

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 9 月 9 日
What happened to the second 0.1 in x? You got rid of the second 0.1 and inserted three new values, 1 11 10
Deepa Maheshvare
Deepa Maheshvare 2019 年 9 月 9 日
Thanks a lot for the repsonse. Please check the edit.

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

 採用された回答

Fabio Freschi
Fabio Freschi 2019 年 9 月 9 日

0 投票

If A is a matrix, I assume you have column vectors, if not, please provide A
% your (column) vector
c = [1 1 3 4 5 6 7 8 11 10].';
iRemove = [2; 9];
iKeep = setdiff(1:length(c),iRemove);
% dummy A
A = rand(length(iKeep));
% your calculation
xReduced = A*c(iKeep);
% preallocation of x
x = zeros(size(c));
% set complete x vector
x(iKeep) = xReduced;
x(iRemove) = c(iRemove);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by