how to get multiple values of multiple columns from a single column?

2 ビュー (過去 30 日間)
Juan Antonio
Juan Antonio 2024 年 3 月 5 日
コメント済み: Dyuman Joshi 2024 年 3 月 8 日
I have a 100x100 matrix where the first column is time and the remaining 99 are % (from 0 to 100%). I would like to know the time value (column 1) where each column reaches the value 40 (40%).
Thank you very much.

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2024 年 3 月 5 日
編集済み: Dyuman Joshi 2024 年 3 月 5 日
Use logical indexing - Find Array Elements That Meet a Condition, for columns 2-100
(Assuming the value 40 occurs same number of times in each column)
You can also use min -
%sample data
y = magic(5)
y = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
%closest value to 16
[v, k] = min(abs(y-16))
v = 1×5
1 2 3 2 0
k = 1×5
1 5 3 2 2
For columns 1:size(y,2) and the corresponding values in k, i.e. row values, are the closest to 16
s = size(y);
y(sub2ind(s, k, 1:s(2)))
ans = 1×5
17 18 13 14 16

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by