What is the difference in these errors?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Haley Inniger
am 3 Apr. 2015
Bearbeitet: James Tursa
am 3 Apr. 2015
In a code I am writing, I keep getting the error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
And I can not find anyone else who has this error. The one I can find is:
In an assignment A(I) = B, the number of elements in A and B must be the same.
Could someone please explain the difference in these errors to me?
0 Kommentare
Akzeptierte Antwort
James Tursa
am 3 Apr. 2015
Bearbeitet: James Tursa
am 3 Apr. 2015
E.g., one way to get these errors:
>> A = rand(3)
A =
0.9649 0.9572 0.1419
0.1576 0.4854 0.4218
0.9706 0.8003 0.9157
>> I = A<0.5
I =
0 0 1
1 1 1
0 0 0
>> A(:) = [1 2 3]
In an assignment A(:) = B, the number of elements in A and B must be the same.
>> A(I) = [1 2 3]
In an assignment A(I) = B, the number of elements in B and I must be the same.
In one case, you are attempting to assign to matrix A using the equivalent of linear indexing and the number of elements doesn't match.
In the other case, you are using a logical matrix to indicate the element positions to replace, and again the number of elements doesn't match.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!