필터 지우기
필터 지우기

How to pick a corresponding value during a for loop run

조회 수: 1 (최근 30일)
joshua Abam
joshua Abam 2019년 11월 26일
편집: joshua Abam 2019년 11월 27일
Hi all please I am in need of your assistance, I am to run a simulation using a for loop which is to pick the 1st score in the 1st run, the 2nd score in the 2nd run, the 3rd score in the 3rd run till the end of the loop. This implies that the 1st run will correspond to the score value of 2345, and the 2nd run will correspond to 345 till the end
Thanks for your help
Kind regards
Joshua
function D_auto = response(x)
;;;;;;;;
;;;;;;;;
Dtetha = 45
Dmax = 360-45
for direction = 0:Dtetha:Dmax
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
scores = [2345,345,87,964,673,9843,763,783]
;;;;;
;;;;;
end
end

채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 26일
편집: Bhaskar R 2019년 11월 26일
It is possible, only if both variable scores and 0:Dtetha:Dmax(direction) lengths are equal
function D_auto = response(x)
% Your calculations
% ;;;;;;;;
% ;;;;;;;;
Dtetha = 45
Dmax = 360-45
% initialize the scores out of the loop
scores = [2345,345,87,964,673,9843,763,783];
k = 1; % counter variable for forloop
for direction = 0:Dtetha:Dmax
% Your calculations
%;;;;;;;;;;;;;;
% ;;;;;;;;;;;;;;
score_value = scores(k); % % it possible till the length of the direction is equal to scores
% Your calculations
% ;;;;;
% ;;;;;
k = k+1; % increment count variable for each iteration
end
end
  댓글 수: 2
joshua Abam
joshua Abam 2019년 11월 26일
편집: joshua Abam 2019년 11월 26일
Dear Bhasker,
Thanks for your help it works perfectly
joshua Abam
joshua Abam 2019년 11월 27일
편집: joshua Abam 2019년 11월 27일
Dear Bhasker,
Just found a way around it
thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by