필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do i skip portions of a loop after getting my answer?

조회 수: 1 (최근 30일)
Clayton
Clayton 2014년 10월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
I am trying to make a loop that modifies a certain value in a matrix and skip to the end of the loop after the modification is made. Right now the value will be modified, but is modified again before the loop can end and I don't know how to fix it.
world = ['#' '.' '.' '.' '.' '.' '#' '.' 'v' '#'
'.' '#' '.' '#' '#' '.' '.' '.' '.' '.'
'.' '.' '#' '#' '.' '.' '#' '#' '.' '#'
'#' '.' '.' '.' '.' '#' '.' '.' '.' '.'
'.' '#' '.' '#' '#' '.' '.' '#' '.' '.'
'.' '#' '.' '.' '.' '#' '#' '#' '.' '#'
'#' '.' '#' '.' '.' '#' '#' '#' '.' '.'
'.' '#' '.' '#' '.' '.' '.' '#' '.' '.'
'.' '.' '.' '#' '#' '.' '#' '.' '#' '.'
'G' '#' '.' '.' '.' '.' '.' '.' '#' '#']
idx = 81; while idx ~= 10; move = input('Your move?(a,w,d,q)','s'); for idx = find(world == 'v'); switch(move) case 'a' world(idx) = '>'; case 'w' [r,c] = find(world == 'v'); world(r,c) = '.'; world(r+1,c) = 'v'; case 'd' world(idx) = '<'; end end for idx1 = find(world == '^'); switch(move) case 'a' world(idx1) = '<'; case 'w' [r,c] = find(world == '^'); world(r,c) = '.'; world(r-1,c) = '^'; case 'd' world(idx1) = '>'; end end for idx2 = find(world == '<'); switch(move) case 'a' world(idx2) = 'v'; case 'w' [r,c] = find(world == '<'); world(r,c) = '.'; world(r,c-1) = '<'; case 'd' world(idx2) = '^'; end end for idx3 = find(world == '>'); switch(move) case 'a' world(idx3) = '^'; case 'w' [r,c] = find(world == '>'); world(r,c) = '.'; world(r,c+1) = '>'; case 'd' world(idx3) = 'v'; end end clc; disp(world); counter = counter + 1

답변 (1개)

Image Analyst
Image Analyst 2014년 10월 15일
I didn't really read/understand that code, but in general to skip portions of code you can use "if", break, or continue commands.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by