Error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" when loading a string into a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I am trying to load to columns of string into a matrix using the following code:
ABC(xy,1) = num2str(pos); ABC(xy,2) = [' ' stri strj];
xy is the index, "pos" is a four digit number and stri & strj are two strings. When the first line runs I get the error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" The variable "pos" is converted successfully but when I try to store it in the array it gives me the error. Using just a single digit works fine.
Any ideas?
Thank you,
Sam
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Jul. de 2011
You cannot have columns of separate strings in any kind of matrix other than a cell array.
Strings are not single objects in MATLAB: they are arrays of characters, so whenever pos has more than one digit, you are trying to store the array with multiple positions in to a single location ABC(xy,1); as you have discovered, that fails.
Consider instead using
ABC{xy,1} = num2str(pos);
ABC{xy,2} = [' ' stri strj];
Or alternately,
ABC(xy,:) = {num2str(pos), [' ' stri strj]};
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!