locating a value of a matrix from another input value

2 ビュー (過去 30 日間)
Jake Bowd
Jake Bowd 2020 年 7 月 13 日
コメント済み: Jake Bowd 2020 年 7 月 13 日
Is there a way you can use a speciifc value i.e. nth value from a vector (i.e. the 24 in the 1x5 double below) to find what the value is for that value in a matrix (point 24 in the 1x101)?
I have a 1x5double --- [24,26,26,26,29]
I have a 1x5structure which holds 5 lots of 1x101double
Many thanks in advance,
Jake

採用された回答

Takumi
Takumi 2020 年 7 月 13 日
ind = [24,26,26,26,29];
S(1).f1 = rand(1,101);
S(2).f1 = rand(1,101);
S(3).f1 = rand(1,101);
S(4).f1 = rand(1,101);
S(5).f1 = rand(1,101);
A = arrayfun(@(x) x.f1(ind),S,'UniformOutput',false);
  3 件のコメント
Takumi
Takumi 2020 年 7 月 13 日
Ok. Using for loop ,most easiest.
ind = [24,26,26,26,29];
S(1).f1 = rand(1,101);
S(2).f1 = rand(1,101);
S(3).f1 = rand(1,101);
S(4).f1 = rand(1,101);
S(5).f1 = rand(1,101);
for i=1:length(ind)
A(i) = S(i).f1(ind(i));
end
Jake Bowd
Jake Bowd 2020 年 7 月 13 日
Hi Takumi,
Thanks. With your assistance, I got the code working:
-------
ind = Results.Average_CFTot1_location;
for x=1:length(Results.Max_Pressure_Total);
S(x).f1 = Results.Max_Pressure_Total(x).Resampled;
end
for i=1:length(ind)
A(i) = S(i).f1(ind(i));
end
-------

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by