Match two variables list

2 ビュー (過去 30 日間)
DavidL88
DavidL88 2022 年 8 月 19 日
編集済み: Les Beckham 2022 年 8 月 19 日
Is there a way to transalte across these variable lists
c = ["80ms,110ms", "110ms,140ms", "140ms,195ms", "195ms,250ms", "250ms,400ms", "400ms,550ms", "550ms,725ms", "725ms,900ms"]
Times = {[0.08, 0.11], [0.11, 0.14], [0.14, 0.195], [0.195, 0.25], [0.25, 0.4], [0.4, 0.55], [0.55, 0.725], [0.725, 0.9]}'
such that if I have str.Var1 = {'80ms,110ms'} I can convert it to Times(1) = [0.08, 0.11]?
I am using the first variable to inform what the input should be (second variable) in a statistics test. So whatever value str.Var1 matches in c I get the correspomding value in Times.
> str.Var1
ans =
1×1 cell array
{'80ms,110ms'}
>> Times(1)
ans =
1×1 cell array
{1×2 double}

採用された回答

Voss
Voss 2022 年 8 月 19 日
編集済み: Voss 2022 年 8 月 19 日
c = ["80ms,110ms", "110ms,140ms", "140ms,195ms", "195ms,250ms", "250ms,400ms", "400ms,550ms", "550ms,725ms", "725ms,900ms"]
c = 1×8 string array
"80ms,110ms" "110ms,140ms" "140ms,195ms" "195ms,250ms" "250ms,400ms" "400ms,550ms" "550ms,725ms" "725ms,900ms"
c_temp = c + ",";
Times = num2cell(reshape(sscanf([c_temp{:}],'%fms,')/1000,2,[]).',2)
Times = 8×1 cell array
{[0.0800 0.1100]} {[0.1100 0.1400]} {[0.1400 0.1950]} {[0.1950 0.2500]} {[0.2500 0.4000]} {[0.4000 0.5500]} {[0.5500 0.7250]} {[0.7250 0.9000]}

その他の回答 (1 件)

Les Beckham
Les Beckham 2022 年 8 月 19 日
編集済み: Les Beckham 2022 年 8 月 19 日
Perhaps what you want is this:
c = ["80ms,110ms", "110ms,140ms", "140ms,195ms", "195ms,250ms", "250ms,400ms", "400ms,550ms", "550ms,725ms", "725ms,900ms"];
Times = {[0.08, 0.11], [0.11, 0.14], [0.14, 0.195], [0.195, 0.25], [0.25, 0.4], [0.4, 0.55], [0.55, 0.725], [0.725, 0.9]}';
str.Var1 = {'80ms,110ms'};
cellresult = Times(strcmp(str.Var1, c));
result = cellresult{1} % extract the double vector from the cell
result = 1×2
0.0800 0.1100

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by