Assign values to an array based on an if statement from a larger array
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
Hi, 
I have an 20 elements array (uint8) in which some elements can be '0' and I want to retrieve the first 8 values that are not '0' and assign them to another array (uint8). 
I am constrained to using only slcilib blocks and submodules so the sorting option is not usable. 
So far I have done something like this 

However, it seems that the for loop never ends and I have to manually stop the model using ctrl + C.
Does anyone have an idea about this issue? 
4 个评论
  Fangjun Jiang
      
      
 2024-2-12
				
      编辑:Fangjun Jiang
      
      
 2024-2-12
  
			I would use the MATLAB Function block. On the other hand, I don't think you are using the For Iterator block correctly. Take a look at the doc and example model.
采纳的回答
  Fangjun Jiang
      
      
 2024-2-12
        
      编辑:Fangjun Jiang
      
      
 2024-2-12
  
      inputArray = [0 1 0 3 0 5 0 7 0 9 0 11 0 13 0 15 0 17 0 19 0 0 20 0 0 21];
index=(inputArray~=0);
tempData=inputArray(index);
outputArray=tempData(1:8)
0 个评论
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


