Subscript assignment mismatch.

13 vues (au cours des 30 derniers jours)
Jonathan Oekland Torstensen
Jonathan Oekland Torstensen le 11 Août 2016
Modifié(e) : Azzi Abdelmalek le 11 Août 2016
Hi.
I run my code, and get this response:
d =[ 0 0.9539 1.0584 1.1880 0.4512
0.9539 0 0.8293 1.1050 1.0646
1.0584 0.8293 0 0.4785 0.7907
1.1880 1.1050 0.4785 0 0.8752
0.4512 1.0646 0.7907 0.8752 0]
Subscripted assignment dimension mismatch.
Error in geomp (line 105)
d(w,w) = [];
>>
The for loop is as follows:
d
for w=1:5
d(w,w) = [];
end
and as you can se, it displays d, but it is not deleting d(1,1), d(2,2) etc.
I have run ismatrix(d) (and gotten 1) as well as size(d), which is 5 5
Whats going on here?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 11 Août 2016
Modifié(e) : Azzi Abdelmalek le 11 Août 2016
If you delete d(1,1) what is the expected result? You can't do it unless d is a cell array
For example:
d=[1 2 3;4 5 6]
If you delete the first element
d(1,1)=[];
What are you expecting as result? is it a matrix? what kind of matrix that rows are not the same size! You can define a cell array
d={1 2 3;4 5 6}
d(1,1)={[]}
  2 commentaires
Jonathan Oekland Torstensen
Jonathan Oekland Torstensen le 11 Août 2016
I would expect a new matrix with one row less.
Azzi Abdelmalek
Azzi Abdelmalek le 11 Août 2016
Modifié(e) : Azzi Abdelmalek le 11 Août 2016
If you want to delete any row:
A=[1 2 3;4 5 6;7 8 9]
idx=2 % the second row to delete
A(idx,:)=[]
If you want to delete the third column:
A=[1 2 3;4 5 6;7 8 9]
idx=3 % the third column to delete
A(:,idx)=[]

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by