Operator '>' is not supported for operands of type 'cell'.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sanley Guerrier
le 8 Déc 2023
Commenté : Sanley Guerrier
le 10 Déc 2023
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 commentaires
Réponse acceptée
Walter Roberson
le 8 Déc 2023
Déplacé(e) : Walter Roberson
le 8 Déc 2023
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 commentaires
Plus de réponses (2)
VBBV
le 8 Déc 2023
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 commentaires
Walter Roberson
le 8 Déc 2023
Nearly the only variable name that you cannot use in a table is Properties .
T = table((1:5).', 'VariableNames', {'T'})
T.T
Stephen23
le 8 Déc 2023
"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
le 8 Déc 2023
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 commentaires
Voss
le 8 Déc 2023
Modifié(e) : Voss
le 8 Déc 2023
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.
Voir également
Catégories
En savoir plus sur Time Series Objects dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!