Effacer les filtres
Effacer les filtres

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

19 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Star Strider
Star Strider le 1 Juin 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 commentaires
Claire Hollow
Claire Hollow le 1 Juin 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.
Star Strider
Star Strider le 1 Juin 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by