how to perform this matrix manupulation..?

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

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 10 Avr 2016
Modifié(e) : Azzi Abdelmalek le 10 Avr 2016

0 votes

Do not label them with different variables, just store them in a cell array

5 commentaires

harshal j
harshal j le 10 Avr 2016
Thank u for your help..but still I am not getting how to write this logic.
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]);
jj=strfind([w 0],[1 0]);
out=arrayfun(@(x,y) v(x:y),ii,jj,'un',0);
celldisp(out)
  1. The first element is out{1}
  2. The second element is out{2}
  3. and so on
harshal j
harshal j le 10 Avr 2016
Modifié(e) : harshal j le 10 Avr 2016
Dear Sir, Thank you so much for your answer. It will solve my problem but I have one more doubt that it is considering the set of non-zero elements, out{1}=30; out{2}=10; out{3}=30, 30, 30; output 1 & 2 is ok but I have a problem with the 3rd output. I want to consider the last elements of the repeated set always. Thank you once again.
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 le 10 Avr 2016
Thank you so much, sir. you have solved my problem, thank you once again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by