Operator '>' is not supported for operands of type 'cell'.
6 次查看(过去 30 天)
显示 更早的评论
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")
采纳的回答
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!