Help with table variables calculation

1 回表示 (過去 30 日間)
Nina Perf
Nina Perf 2022 年 5 月 9 日
編集済み: Nina Perf 2022 年 5 月 14 日
Hi,
I have a
table 'T'
with a column variable named 'rank', which includes categorical numbers: from 1 to 3.
I want to check if the 'rank' numbers are below or equal to 2. I do that with this:
i12 = (str2num(char(T.rank)) <= 2);
I need help with the following:
If i12 is True, then I want to reassign the rank to be '2'.
So, in the end, I have the variable 'rank' going from 2 to 3.
  1 件のコメント
Rik
Rik 2022 年 5 月 10 日
編集済み: Rik 2022 年 5 月 10 日
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
This page is now on archived on the Wayback Machine.

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

採用された回答

Clay Swackhamer
Clay Swackhamer 2022 年 5 月 9 日
% Define the table
T = table;
T.rank = [1,3,2,4,2,5,1,3,2,4]';
T.rank = categorical(T.rank);
% Create another column to store the 2s
T.updatedRank = 2*ones(height(T),1);
T.updatedRank = categorical(T.updatedRank);
% Find values <= 2
ix = str2num(char(T.rank)) <= 2; % True for rank 1 and 2
% Replace values
T.rank(ix) = T.updatedRank(ix)
% Get rid of updated rank column (optional)
% T.updatedRank = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by