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

19 次查看(过去 30 天)
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!

采纳的回答

Star Strider
Star Strider 2020-6-1
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 个评论
Claire Hollow
Claire Hollow 2020-6-1
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by