Azzera filtri
Azzera filtri

how to concatenate a result of a loop to a single 2D mtrixa

1 visualizzazione (ultimi 30 giorni)
Hi, I have the following code to find the linear index and the associated values of connected points in a matrix
a=[0 1 1 0 0 0
1 1 1 0 2 2
0 0 0 0 2 2
0 0 0 0 0 0]
a_connected=bwlabeln(a);
%region properties of matrix a
cc2=bwconncomp(a_connected);
stats_a=regionprops(cc2,'pixellist','pixelidxlist');
% Extracting the connected objects and their index information
% For Test Matrix
arr_test=[];
tss=[];
for k=1:numel(stats)
idx_test=stats(k).PixelIdxList;% gives linear index
Pixels_in_region_test=test_connected(idx_test);% associated val
arr_test=[idx_test,Pixels_in_region_test]
end
I want to create an output matrix that will store the result of loop but so far been unable. the matrix only stores the value from the final iteration of the loop. I have used cat but it does not work.
Any ideas on how to or what i am doing wrong?
Thanks

Risposta accettata

Romendra
Romendra il 31 Gen 2012
okay, so the cat function does not work in this case but the vertcat sure did. Just added a little if loop in this
arr_test=[];
tss=[];
for k=1:numel(stats)
idx_test=stats(k).PixelIdxList;
Pixels_in_region_test=a_connected(idx_test);
if k==1
arr_test=[idx_test,Pixels_in_region_test]
else
tss=[idx_test,Pixels_in_region_test]
arr_test=vertcat(arr_test,tss)
end
end

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by