Help with conditional statement

1 回表示 (過去 30 日間)
Mike Raymond
Mike Raymond 2018 年 10 月 3 日
コメント済み: Mike Raymond 2018 年 10 月 3 日
I'm trying to create a conditional statement, using the code below. This code attempts to replace the unit name with a new unit name if the CC Key is greater than zero; otherwise, use the previous unit name:
if any(Table1.CC_KEY == 0);
Table1.NEW_UNITNAME = Table1.UNIT_NAME;
else
Table1.NEW_UNITNAME = Table1.UNIT_CC;
end
  2 件のコメント
Adam
Adam 2018 年 10 月 3 日
編集済み: Adam 2018 年 10 月 3 日
So what is the question? Does it not work? If not what does it do wrong? You seem to be testing for equality against 0 yet your comment says it is testing > 0. I assume the key cannot be negative then.
Mike Raymond
Mike Raymond 2018 年 10 月 3 日
Thanks! In my case, if the CC Key is greater than zero, then the previous unit name appears as the new unit name...and if the CC Key is zero, then the previous unit name appears as well. In others, regardless of the CC Key value, the previous unit name appears as the new name. Does this make sense?

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2018 年 10 月 3 日
If I understand correctly what you want to do, you want to rename one of the variables in your table. Is that correct? If so you could assign the contents of that variable to another then delete the old variable, or you could just change the name of the variable.
Note that some of the functions listed on that first documentation page to which I linked were introduced fairly recently (the removevars function was added in release R2018a, for example) so they won't be available if you're using an older release. But I believe some of the deletion techniques as well as the variable renaming technique will work for all releases containing table.
  1 件のコメント
Mike Raymond
Mike Raymond 2018 年 10 月 3 日
Steven, much appreciated! Actually, I'd like to change the variable names only when the CC Key is greater than zero. Otherwise, I want to leave the variable names unchanged. So, unfortunately, I'm not sure this approach would work. Again, thanks for taking the time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLanguage Support についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by