フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to find the index for the following code

1 回表示 (過去 30 日間)
jaah navi
jaah navi 2019 年 2 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
If A=1:10,%A= 1 2 3 4 5 6 7 8 9 10
But I want to display the index of A using for loop.
Could anyone help me to solve the issue.
  3 件のコメント
jaah navi
jaah navi 2019 年 2 月 19 日
when A=1:10 it displays the number from 1 to 10.
I want to have the expected output in the following manner.
when A=1,I want to display one number with respect to first element.
when A=2,i want to display one number with respect to second element.
...
when A=10,i want to display one number with respect to last element.
could you please help me on this.
Rik
Rik 2019 年 2 月 19 日
Can't you just use A as an index?
someData=[5 8 7 4 6 9 3 10 7 2];
A=5;
disp(someData(5))%shows the 5th element (6 in this case)
%or in a loop:
for A=1:10
disp(someData(A))
end

回答 (1 件)

madhan ravi
madhan ravi 2019 年 2 月 20 日
編集済み: madhan ravi 2019 年 2 月 20 日
“But I want to display the index of A using for loop”
You don’t need one , see the documentation of fprintf().
Values=rand(1,10); % example data
A=1:numel(Values); %indices
fprintf('When A = %d the value is %d\n',[A;Values])

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by