필터 지우기
필터 지우기

How to run completely a loop inside one other?

조회 수: 1 (최근 30일)
EM geo
EM geo 2019년 3월 6일
댓글: EM geo 2019년 3월 6일
Hi! i have the data attached. ID_stop1 is an identifier of data and it is repeated 80 times for each value. Nn1 is a number from 1 to 20 and it is still repeated for each unique value of ID_stop1. Bn1 is a number from 1 to 20 and it is repeated for each unique value of Nn1. I need to access to data of L1 for each ID_stop1 and each Nn1. I created this code that works but at the end of the second loop it stops. How can i come back to the first loop?
I would like to have a cell array of 20 cells, and for each cell there should be 20 sub cells.
Any helps?
load ('sclerometrica_equotip_v1')
misure = [ID_stop L Nn Bn];
% misure(any(isnan(misure), 2), :) = [];
ID_stop1 = misure(:,1);
L1 = misure(:,2);
Nn1 = misure(:,3);
Bn1 = misure(:,4);
k = unique(ID_stop1);
for i = 1:numel(k)
index = (ID_stop1 == k(i));
N= Nn1(index); %battute nodi
j = unique(N);
for m = 1:numel(j)
index2 = (N == j(m));
L_nodo = L1(index2);
result{m} = L_nodo;
end
end

채택된 답변

Bob Thompson
Bob Thompson 2019년 3월 6일
I suspect that the issue is not that the code actually stops, but that the results are only recorded for one internal loop. If you want cells inside of cells then you need to index for each loop.
results{i}{m} = L_nodo;
  댓글 수: 10
EM geo
EM geo 2019년 3월 6일
maybe there is something wrong with the indexing... i put a debug marker in the beginning of the first for loop
EM geo
EM geo 2019년 3월 6일
i solved the problem, now it works good!!
k = unique(ID_stop1);
for i = 1:numel(k)
index = (ID_stop1 == k(i));
nn = Nn1(index);
bn = Bn1(index);
ll = L1(index);
j =unique(nn);
for ii= 1:numel(j)
index1 = (nn == j(ii));
Lnodo = ll(index1);
result{i}{ii} = Lnodo;
end
end
Thank you for your suggestions!!! :)

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by