0

미안하지만이 질문은 유감스러운 질문 일 수 있습니다. 그것은 세포 배열과 관련이 있습니다.MATLAB의 여러 루프에서 셀 배열의 관련 데이터를 저장하고 추출하십시오

나는 내가 어떤 문제가있을 경우에만 일부를 물어 예를 제공하기 위해 노력했다 delay, offset, and threshold.

delay = [0.01:0.01:0.03]; 
offset = [0.02:0.01:0.04]; 
threshold = [0.4:0.1:0.9];  
limit_for_idx = [0.4:0.1:0.9]; 
limit = [0.4:0.1:0.9]; 

있습니다.

루프의 첫 번째 부분에서 모든 루프에 대해 그림에서와 같이 Delay, Offset, J, r, 임계 값에 대한 완전한 값을 받았습니다.

enter image description here

J=16 25 24 25r = 24 21 46 18threshold = 0.4:0.9

delay =0.0300offset=0.0400

는 그럼 J의 최소값과 최대 J 및 R을 R min으로 대응하는 임계 값의 최대 값을 여과 하였다. 나는 그림에서와 같이이 값들을 받았습니다.
[min_J,min_J_loc] = min(J(:)) 
    [max_r,max_r_loc] = max(r(:)) 
    thresh_min_J = threshold(min_J_loc); 
    thresh_max_r = threshold(max_r_loc); 
내가 빨간색으로 표시했지만 전체 그림에 표시된 것처럼 모든 루프 이러한 조합을 수신 할 하나의 사례를 들어

enter image description here

.

질문 :

내가 delay의 조합을 필요로 필요로하는 모든 조합, offset에서 그림 같이 내가 minimum Jmaximum r을 포함 delay, offset, threshold의 조합을 찾으려 • 포함 thresholdminimum Jmaximum r. 셀 배열에서 조합을 가져 오는 방법을 혼란스럽게하면서 셀 배열에 값을 저장했습니다.

값을 저장하는 좋은 방법이 있습니까? 예를 들어 누군가가 작은 힌트가 어떻게 작동하는지 설명 할 수 있다면 구조가 될 수 있습니다.

코드 :

delay = [0.01:0.01:0.03]; 
offset = [0.02:0.01:0.04]; 
threshold = [0.4:0.1:0.9];  
limit_for_idx = [0.4:0.1:0.9]; 
limit = [0.4:0.1:0.9];   


J=0; 
T = 1; 
b=1; 
K=1; 
for H = 1:numel(delay) 
    for G = 1:numel(offset) 
     for R = 1:numel(threshold); 

      J = randi([10 25],1,4);  
      r = randi([10 50],1,4); 
     end 
    [min_J,min_J_loc] = min(J(:)) 
    [max_r,max_r_loc] = max(r(:)) 
    thresh_min_J = threshold(min_J_loc); 
    thresh_max_r = threshold(max_r_loc); 
     out{K,:} = [ delay(H) offset(G) J r threshold]; 
     output{T,:} = [delay(H) offset(G) min_J max_r thresh_min_J thresh_max_r]; 
    K=K+1; 
    T = T+1; 
    end 

end 


    for X = 1:numel(out) 
     disp(' delay , offset(G) , J, r , threshold ') 
     Q = out{X}; 
     disp(Q) 
    end 

    for X = 1:numel(output) 
     disp(' delay , offset(G) , min_J, max_r , thresh_min_J thresh_max_r ') 
     Z = output{X}; 
     disp(Z) 

    end 
+1

"그림 _에서와 같이 최소 J 및 최대 r을 포함하는 _"이라고 말한 경우. 'thresh'를 의미합니까? 'J'도 최소이거나'r' 최대 값을 갖지 않기 때문에 ... 빨간색 프레임이있는 이미지는 최소값/최대 값을 찾은 결과를 보여줍니까? 조금 혼란 스럽습니다. –

+0

먼저 첨부 된 그림을 보시기 바랍니다. 'J'와 'r'과 같은 값을 포함합니다. 0.0300 0.0400'16.0000 25.0000 24.0000 25.0000 'r'24.0000 21.0000 46.0000 18.0000' 임계 값 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000' – Peter

+0

그런 다음 최소 J 및 최대 r 값을 필터링하기 위해 로직을 적용했습니다. 지연, 오프셋 G), min_J, max_r, thresh_min_J thresh_max_r' ' 0.0300 0.0400 16.0000 46.0000 0.4000 0.6000' – Peter

답변

1

체크 아웃 귀하의 예제의 수정 된 버전 :

function varargout = q47452082 
delay = (0.01:0.01:0.03); 
offset = (0.02:0.01:0.04); 
threshold = (0.4:0.1:0.9); 
nD = numel(delay); 
nO = numel(offset); 
J = randi([10 25],1,4,nD,nO); 
r = randi([10 50],1,4,nD,nO); 
%% Preallocate 
%{ 
The simplest way to do it: 
out = NaN(nD*nO,3*1+2*4); 
output = NaN(nD*nO,6); 
%} 
out = struct('delay',[],'offset',[],'J',[],'r',[],'threshold',[]); 
out = repmat(out,nD*nO,1); 
output = struct('delay',[],'offset',[],'min_J',[],'max_r',[],... 
    'thresh_min_J',[],'thresh_max_r',[]); 
output = repmat(output,nD*nO,1); 
fn{2} = fieldnames(output); 
fn{1} = fieldnames(out); 
%% Populate the data structures: 
K = 1; 
for H = 1:numel(delay) 
    for G = 1:numel(offset) 
    [min_J,min_J_loc] = min(J(:,:,H,G)); 
    [max_r,max_r_loc] = max(r(:,:,H,G)); 
    thresh_min_J = threshold(min_J_loc); 
    thresh_max_r = threshold(max_r_loc); 
    data = {delay(H),offset(G),J(:,:,H,G),r(:,:,H,G),threshold}; 
    for indF = 1:numel(fn{1}) 
     out(K).(fn{1}{indF}) = data{indF}; 
    end 
    data = {delay(H), offset(G), min_J, max_r, thresh_min_J, thresh_max_r}; 
    for indF = 1:numel(fn{2}) 
     output(K).(fn{2}{indF}) = data{indF}; 
    end 
    K = K+1; 
    end 
end 

if nargout == 0 % if no outputs requested, print 
    if ~verLessThan('matlab','8.2') % tables exist in MATLAB R2013b or newer 
    disp(struct2table(out)); 
    disp(struct2table(output)); 
    else 
    for X = 1:numel(out) 
     Q = out(X); 
     disp(Q) 
    end 
    for X = 1:numel(output) 
     Z = output(X); 
     disp(Z) 
    end 
    end 
else % otherwise output the desired data: 
    % OPTION #1: separate variables 
    % You should call the function like so: [min_J_cases,max_r_cases] = q47452082(); 
    varargout{1} = output([output.min_J] == min([output.min_J])); 
    varargout{2} = output([output.max_r] == max([output.max_r])); 
    % OPTION #2: 1 output, 2x1 cell 
    %{ 
    varargout = {output([output.min_J] == min([output.min_J]));... 
       output([output.max_r] == max([output.max_r]))}; 
    %} 
    % OPTION #3: 1 output, 2x1 struct 
    %{ 
    varargout = {[output([output.min_J] == min([output.min_J]));... 
       output([output.max_r] == max([output.max_r]))]}; 
    %} 
end 

몇 가지 당신이주의해야합니다

  • 가 좀되지 않은 변수를 제거했습니다.
  • outoutputstruct 어레이로 사전 할당했습니다.
  • 임의의 번호 생성을 루프 이전에 이동 시켰습니다 .
  • 배열에 dynamic field references을 사용하여 할당을 수행합니다.
  • 다른 MATLAB 버전 (따라서 지원되는 기능이 다름)에 따라 다른 코드를 실행하는 방법에 대한 데모를 추가했습니다. 끝 부분의 인쇄를 참조하십시오.
  • 출력 기능을 요청하지 않는 경우에만 기능이 인쇄됩니다.
  • 코드를 더 벡터화 (예 : 루프 제거) 할 가능성이 있습니다.
+1

정성을 다한 답장을 보내 주셔서 감사합니다. 코드를 깊이 살펴보고 언젠가는 나에게 약간의 시간을 주셔서 감사드립니다. – Peter

+0

@ De-Vil 가장 먼저 늦은 피드백에 대해 사과드립니다. 귀하의 솔루션에 대해 고마워요. 그것은 효과가 있었다. 나는 그것을 나의 필요에 따라 더 수정했지만 완벽하게 작동하고있다. 시간과지도에 감사드립니다. – Peter

+1

@ 피터 환영합니다! –

관련 문제