Borrar filtros
Borrar filtros

"The value on the right-hand side of the assignment has the wrong width." Error

19 visualizaciones (últimos 30 días)
Hello! I have a very large table and I am trying to change every time it says ',,7' in column 10 to change the corresponding column 9 to 'NA'. As far as I know, this following code should work
idx=station001_eus{:,10}==(',,7');
station001_eus{idx,9}='NA';
except I keep getting the error
The value on the right-hand side of the assignment
has the wrong width. The assignment requires a
value whose width is 1.
for the second line. Any ideas how to get past this? I can't find much on it. Thank you!

Respuesta aceptada

Star Strider
Star Strider el 1 de Jun. de 2020
I am not certain where the problem is in the two lines you posted.
Try this:
idx= strcmp(station001_eus{:,10}, ',,7');
station001_eus{idx,9}="NA";
The first uses strcmp to compare the strings, usually preferable to the equality test using ==. The second uses a string element (instead of a character array) for the replacement. They have properties similar to numerical elements, so might be appropriate here. (Another option, of course, might be setting it to NaN.)
I obviously can’t test this with your table, so I leave that to you to experiment with. I will help as I can if there are still problems.
  8 comentarios
Claire Hollow
Claire Hollow el 1 de Jun. de 2020
Thank you so much for your help and suggestions. I'm going to continute to play around with it and see what I can find.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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!

Translated by