Set negative values to zero in just one column of tables in 1 x 71 cell

3 ビュー (過去 30 日間)
BN
BN 2020 年 1 月 29 日
回答済み: Allen 2020 年 1 月 29 日
I have 1 x 71 cell arrays that contain 71 tables. I want to set all negative values in the rrr24 column of all tables into zero. I tried some ways but always I get various errors:
first try:
headers = {'rrr24'};
for i = 1:numel(C)
colIdx = ismember(C{i}.Properties.VariableNames, headers);
C{i}(:,colIdx)< 0 = 0
end
Second try:
headers = {'rrr24'};
index=find(C.Properties.VariableNames, headers <0);
precip(index)=0;
Any advice is appreciated.
Thank You

採用された回答

Allen
Allen 2020 年 1 月 29 日
Assuming that each table contains a variable name of 'rrr24', then the following should work.
for i=1:length(C)
C{i}{C{i}{:,'rrr24'}<0,'rrr24'} = 0;
end
If it is possible that 'rrr24' is not a variable name for one or more of the tables, then you can add an if-statement to check for its existance first.
for i=1:length(C)
if any(contains(C{i}.Properties.VariableNames,'rrr24'))
C{i}{C{i}{:,'rrr24'}<0,'rrr24'} = 0;
end
end

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by