how to perform this matrix manupulation..?

1 回表示 (過去 30 日間)
harshal j
harshal j 2016 年 4 月 10 日
コメント済み: harshal j 2016 年 4 月 10 日
hi, I have a row matrix eg [30,0,0,0,0,10,0,0,0,0,30,30,30,0,0,0,0,0,10....] I have to consider first element i.e 30 (and label it by 'a') then I have to discard the elements between 30 and 10. then I have to consider first 10 (and label it by 'b'),again I want to discard the elements between the 10 and last 30 ( also want to discard the first two elements whose value is 30 and consider the last 30(and label it by 'c') ) I want to repeat the same steps for the entire row matrix whose size is 1x2000. I don't know how to do this. Please help me to write this matrix logic. Thanks in advance

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 10 日
編集済み: Azzi Abdelmalek 2016 年 4 月 10 日
Do not label them with different variables, just store them in a cell array
  5 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 10 日
v=[30,0,0,0,0,10,0,0,0,0,30,30,30,0,0,0,0,0,10];
w=v~=0;
ii=strfind([0 w],[0 1]);
out=arrayfun(@(x) v(x),ii,'un',0);
celldisp(out)
harshal j
harshal j 2016 年 4 月 10 日
Thank you so much, sir. you have solved my problem, thank you once again.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by