Operator '>' is not supported for operands of type 'cell'.
2 ビュー (過去 30 日間)
古いコメントを表示
Sanley Guerrier
2023 年 12 月 8 日
コメント済み: Sanley Guerrier
2023 年 12 月 10 日
Can someone help with the logical operator " extract rows +/- 1 where columns T And V are not zero"? Thank you!
clear
close all
clc
T1= readtable("Performance history + distress ( d-3) reduced.xls",VariableNamingRule="preserve");
T2 = readtable("D-3 Road sections (HPMA) Tran red v2.xlsx",VariableNamingRule="preserve");
% Join tables
joinedData = innerjoin(T2,T1,"LeftKeys",["FROM_REFP","TO_REFP"],"RightKeys",...
["begin_refp","end_refp"]);
T = joinedData;
T.Properties.VariableNames = num2cell(char(64+(1:size(T,2))));
%Set the empty cell "iri" ==0
if isempty(T{:,22})
T(:,22) =0;
end
% set H = G where H == 0
idx = T.H == 0;
T.H(idx) = T.G(idx);
% extract rows +/- 1 where columns T And V are not zero
idx = T.T>0 | T.V >0;
idx = any([idx [false; idx(1:end-1)] [idx(2:end); false]],2);
TT= T(idx,:); %extracted_rows
writetable(TT, "Merged&CleanData.csv")
6 件のコメント
採用された回答
Walter Roberson
2023 年 12 月 8 日
移動済み: Walter Roberson
2023 年 12 月 8 日
filename = 'T.xlsx';
opt = detectImportOptions(filename);
opt = setvaropts(opt, [2:6,13:15,18:19], 'Prefixes', "'", 'Suffixes', "'");
T = readtable(filename, opt);
T.Properties.VariableNames = num2cell(char(64+(1:size(T,2))));
mask = T.T ~= 0 & ~strcmp(T.R, "");
mask = conv(mask, [1 1 1], 'same') > 0;
selected_rows = T(mask,:);
selected_rows
5 件のコメント
その他の回答 (2 件)
VBBV
2023 年 12 月 8 日
T is a table array/datatype, and you try to access variable inside the table with same name , this is not valid operation
idx = T.T>0 | T.V >0; %T.T is not valid operation
7 件のコメント
Walter Roberson
2023 年 12 月 8 日
Nearly the only variable name that you cannot use in a table is Properties .
T = table((1:5).', 'VariableNames', {'T'})
T.T
Stephen23
2023 年 12 月 8 日
"T.T is not valid operation"
Why not?
T = array2table(pi, "VariableNames","T")
T.T % why do you think that this is "not valid operation" ?
Voss
2023 年 12 月 8 日
T = readtable('T.xlsx');
T.Properties.VariableNames = num2cell(char(64+(1:size(T,2))))
"extract rows +/- 1 where columns T And V are not zero"
idx = T.T ~= 0 & T.V ~= 0;
idx = any([idx [false; idx(1:end-1)] [idx(2:end); false]],2);
result = T(idx,:)
3 件のコメント
Voss
2023 年 12 月 8 日
編集済み: Voss
2023 年 12 月 8 日
T = readtable('T.xlsx');
T.Properties.VariableNames = num2cell(char(64+(1:size(T,2))));
"extract non empty rows in Column R that correspond to nonzero row in column T and add +/- 1 rows"
idx = T.T ~= 0 & ~strcmp(T.R,char([39 39]));
% idx = T.T ~= 0 & ~strcmp(T.R,''''''); % alternate, equivalent to the above
idx = any([idx [false; idx(1:end-1)] [idx(2:end); false]],2);
result = T(idx,:)
For this purpose, I considered the 1x2 character vector where each element is the single quote character (i.e., the character vector char([39 39])) to be the "empty" entries in column R you want to avoid. No doubt using setvaropts as in Walter's approach results in a table whose contents are easier to deal with.
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!