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

조회 수: 22 (최근 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