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

29 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Star Strider
Star Strider am 1 Jun. 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 Kommentare
Claire Hollow
Claire Hollow am 1 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by