Index of element to remove exceeds matrix dimensions.
Afficher commentaires plus anciens
In my code x tends to change from 1 to 7. Here I took a sample value as 4. I want to delete the array element, if it has less than 0 or greater than 8 otherwise save the value in the array. xplus is an 1-D array. xplus maximum value will be 7 values. I tried this code it is getting error as
ERROR: Index of element to remove exceeds matrix dimensions.
Error in deletearraytest (line 5) xplus(x1)=[];
and workspace variable x=4 , x1=7, xplus=[5;6;7;8;0]
Here is my code x=4; xplus=zeros(7,1); for x1=1:7 if((x+x1<=0)||(x+x1>8)) xplus(x1)=[]; else xplus(x1)=x+x1; end end
I have check the solutions of many links but, I cant understand the mistake I did. Many people said that when we are going to delete the array element, it not going to be previous size. I need more explanation in that and solve my problem. I am amateur matlab user. Help needed. Thanks in advance.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!