フィルターのクリア

String operations on dynamic dataset

1 回表示 (過去 30 日間)
klb
klb 2021 年 2 月 8 日
編集済み: klb 2021 年 2 月 13 日
Hi everyone,
Number of machines activated and hence the duration timestamp, varies each day so the dataset dimention is dynamic.
I am trying to extract the dataset for each machine. Cant get my extractBetwen () to work.
w=[ "Mac_A"
"1 9:53.3"
"2 9:23.5"
"3 2:16.2"
"4 2:45.6"
"5 12:01.2"
"Mac_B"
"1 23:56.5"
"2 28:12.6"
"3 15:34.1"
"4 19:23.0"
"5 1:38.4"
"Mac_C"
"1 11:35.6"]
% ..
% many more machines and thier datasets
l=length(w(strlength(w)==5)) % counts how many machines
for e=1: length(w)
start = w(strlength(w)==5)
stop = w(strlength(w)<8)
itsdata(data(l),:) = extractBetween(w,start,stop) % cant get this to work.
end
expected output is vectors which are the datasets of the machines.
["1 9:53.3,2 9:23.5,3 2:16.2,4 2:45.6,5 12:01.2"]
["1 23:56.5 , 2 28:12.6,3 15:34.1,4 19:23.0,5 1:38.4"]
["1 11:35.6"]
..
.. %more vectors

採用された回答

Jan
Jan 2021 年 2 月 9 日
編集済み: Jan 2021 年 2 月 11 日
w=[ "Mac_A"
"1 9:53.3"
"2 9:23.5"
"3 2:16.2"
"4 2:45.6"
"5 12:01.2"
"Mac_B"
"1 23:56.5"
"2 28:12.6"
"3 15:34.1"
"4 19:23.0"
"51:38.4"
"Mac_C"
"1 11:35.6"];
Sep = [find(startsWith(w, 'Mac_')); numel(w) + 1];
n = numel(Sep) - 1;
itsdata = strings(n, 1);
for k = 1:n
itsdata(k) = [w{Sep(k)+1:Sep(k+1)-1}];
end
The command extractBetween() cuts out a piece of a string, not an array of strings between indices.
  7 件のコメント
Jan
Jan 2021 年 2 月 13 日
w=[ "Mac_A"; "1 9:53.3"; "2 9:23.5"; "3 2:16.2"; ...
"4 2:45.6"; "5 12:01.2"; "Mac_B"; "1 23:56.5"; ...
"2 28:12.6"; "3 15:34.1"; "4 19:23.0"; "5 1:38.4"; ...
"Mac_C"; "1 11:35.6"];
Sep = [find(startsWith(w, 'Mac_')); numel(w) + 1]
n = numel(Sep) - 1;
itsdata = strings(n, 1);
for k = 1:n
itsdata(k) = join(w(Sep(k)+1:Sep(k+1)-1), ',');
end
itsdata
klb
klb 2021 年 2 月 13 日
編集済み: klb 2021 年 2 月 13 日
Jan, Thank you so very much!
This expresion : Sep = [find(startsWith(w, 'Mac_')); numel(w) + 1], is complex so broke it into its elements and echoed each output. I understand that logic as well now. Thank you again for your time.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by