Is there any equivalent keyword 'goto' in matlab not in simulink but in matlab coding
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Aakriti Srivastava
 am 27 Jun. 2022
  
    
    
    
    
    Beantwortet: Jan
      
      
 am 27 Jun. 2022
            I want to pass control to other section of code if certain condition becomes true something like this we do in C, code snippet attached for reference. 
for k = ele_search_start_edx : ele_search_end_idx
    if data(k) =='C' && data(k+1) == '='
        Element_arr(n) = extraxtBetween(data(ele_search_start_idx : ele_search_end_idx),['=','{',' '],['}',' ','Q'])
        n= n+1;
        goto next_node_search_function
    elseif data(k) == 'N'
        Element_arr(n) = extractBetween(data(ele_search_start_idx1 : ele_search_end_idx1),['=','{',' '],[' ','}'])  
        n= n+1;
        goto next_node_search_function
    elseif data(k) =='L' && data(k+1) == '='
        Element_arr(n) = extraxtBetween(data(ele_search_start_idx : ele_search_end_idx),['=','{',' '],['}',' ','Q'])
        n= n+1;
        goto next_node_search_function
    end
end
0 Kommentare
Akzeptierte Antwort
  Jan
      
      
 am 27 Jun. 2022
        No, there is no GOTO in Matlab and it should be avoided strictly in good code.
Maybe:
function YourFunc
n = 123;  % ???
for k = ele_search_start_edx : ele_search_end_idx
    if data(k) =='C' && data(k+1) == '='
        Element_arr(n) = extraxtBetween(data(ele_search_start_idx : ele_search_end_idx),['=','{',' '],['}',' ','Q'])
        break;
    elseif data(k) == 'N'
        Element_arr(n) = extractBetween(data(ele_search_start_idx1 : ele_search_end_idx1),['=','{',' '],[' ','}'])  
        break;
    elseif data(k) =='L' && data(k+1) == '='
        Element_arr(n) = extraxtBetween(data(ele_search_start_idx : ele_search_end_idx),['=','{',' '],['}',' ','Q'])
        break
    end
end
next_node_search_function(ElementArr, n + 1)
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Downloads finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!