How to run completely a loop inside one other?

3 views (last 30 days)
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

Accepted Answer

Bob Thompson
Bob Thompson on 6 Mar 2019
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 Comments
EM geo
EM geo on 6 Mar 2019
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 on 6 Mar 2019
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!!! :)

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!