Find the first matched string/value from a table
14 次查看(过去 30 天)
显示 更早的评论
Hi,
I have got a table like below:
StepNum Activity TypeNum
5098 Stand 1-96
5099 Stand 1-96
5101 Stationary 1-96
5105 Stationary 1-96
5106 Stand 1-97
5107 Stand 1-97
5113 Stand 1-97
5114 Trenching 1-98
5115 Trenching 1-98
5116 Trenching 1-98
What I would like to do is to find the first matched of the string 'Trenching', then read the row/column number so that I can get the value/string in adjacent cells/rows. Just wondering if anyone here can help me out? Many thanks in advance.
Regards,
Kane
0 个评论
采纳的回答
Star Strider
2023-6-13
One approach —
VN = {'StepNum' 'Activity' 'TypeNum'};
step = [5098
5099
5101
5105
5106
5107
5113
5114
5115
5116];
v23 = ["Stand" "1-96"
"Stand" "1-96"
"Stationary" "1-96"
"Stationary" "1-96"
"Stand" "1-97"
"Stand" "1-97"
"Stand" "1-97"
"Trenching" "1-98"
"Trenching" "1-98"
"Trenching" "1-98"];
T1 = table(step, v23(:,1), v23(:,2), 'VariableNames',VN)
idx = find(ismember(T1{:,2}, "Trenching"));
DesiredResult = T1{idx(1),:} % Contents Of Row
DesiredResult = T1(idx(1),:) % Sub-Table
.
4 个评论
Star Strider
2023-6-15
My pleasure!
Try this (including a calculation for ‘R’) —
T1 = readtable('activity_table.xlsx', 'VariableNamingRule','preserve')
VN = T1.Properties.VariableNames;
idx = find(ismember(T1{:,2}, "Trenching"))
DesiredResult = T1(idx(1)+[-1 1],:) % Contents Of Row
Volt = DesiredResult{:,ismember(VN,'Voltage(V)')}
Current = DesiredResult{:,ismember(VN,'Current(A)')}
R = (Volt(2) - Volt(1)) / (Current(2) - Current(1))
See if that does what you want.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!