Operator '>' is not supported for operands of type 'cell'.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sanley Guerrier
am 8 Dez. 2023
Kommentiert: Sanley Guerrier
am 10 Dez. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Dez. 2023
Verschoben: Walter Roberson
am 8 Dez. 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 Kommentare
Weitere Antworten (2)
VBBV
am 8 Dez. 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 Kommentare
Walter Roberson
am 8 Dez. 2023
Nearly the only variable name that you cannot use in a table is Properties .
T = table((1:5).', 'VariableNames', {'T'})
T.T
Stephen23
am 8 Dez. 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
am 8 Dez. 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 Kommentare
Voss
am 8 Dez. 2023
Bearbeitet: Voss
am 8 Dez. 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.
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!