Finding corresponding values between array

5 ビュー (過去 30 日間)
JaffaCakes
JaffaCakes 2021 年 4 月 28 日
コメント済み: JaffaCakes 2021 年 4 月 28 日
Hi, Suppose I have any matrix A(1,j) where j is columns
and t from 0:5:30
and for each value of t I have a corresponding j value
so e.g. t= 0 5 10 15 20 25 30
and j= 1 11 21 31..... corresponding to the t values.
How can I find an element within matrix A, corresponding to each of j values (columns)?
I've tried to do something like this so far,but it didnt work.
t= 0 5 10 15 20 25 30
j= 1 11 21 31.....
v=length(t)
for k=1:v
y=A(1,J(v))
end

採用された回答

Steven Lord
Steven Lord 2021 年 4 月 28 日
I'm not certain I understand your question. Let's take a concrete example. Can you tell us what the answer you'd want to receive for this example is and how you calculated that answer?
t = 0:5:30;
j = 1:10:61;
A = (1:61).^2;
Is it as simple as indexing?
y = A(1, j)
y = 1×7
1 121 441 961 1681 2601 3721
results = table(t.', j.', y.', j.'.^2, ...
'VariableNames', ["t", "j values", "y values", "j^2 to check"])
results = 7×4 table
t j values y values j^2 to check __ ________ ________ ____________ 0 1 1 1 5 11 121 121 10 21 441 441 15 31 961 961 20 41 1681 1681 25 51 2601 2601 30 61 3721 3721
  2 件のコメント
JaffaCakes
JaffaCakes 2021 年 4 月 28 日
編集済み: JaffaCakes 2021 年 4 月 28 日
Hi, the problem is, I can't index like you've written because J is given by an equation (not as simple as the one i've shown here)
t=0:5:30
J=2*t+1 %j is given by an equation, would like to take these values of J and input into the matrix column
y=A(1,J) %gives an error saying, index exceeds matrix dimensions
JaffaCakes
JaffaCakes 2021 年 4 月 28 日
Hi, nm I've sorted it out. Thanks for the help though

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by