How to run completely a loop inside one other?

3 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by