Hello everybody, I have two data vectors: d1 and d2, I have passed them through a segmentation algorithm, and the resulted class indexes are IDX1 and IDX2. Number of members in each segment are segMem1 for d1 and segMem2 for d2. Now I want to assign one index to each component in d1 (and d2), according to segMem1 (and segMem2). Moe specifically, I want to index the 3 first components of d1 as 1 1 1, the two next components as 2 2 , the 2 third components as 1 1 and so on, and at last I want to have 1 1 1 2 2 1 1 3 4 4 for d1. I have written the following code, and it seems to work for indexing d1. But I don't know how to make another loop to generalize this to both d1 and d2?
clear allclose allclc% data
d1 = [10 3 44 33 4 16 7 10 22 54]; d2 = [3 24 35 12 3 4 7];IDX1 = [1 2 1 3 4];IDX2 = [3 1 2 1];segMem1 = [3 2 2 1 2]; % Determines how many times each index in IDX1 should be repeated.
segMem2 = [2 1 2 2];%%Now assign indexes to data vector
n = 1;a = cell(1,length(d1)); for k = 1:length(segMem1) for j = n:segMem1(k)+n-1 a{j} = IDX1(k); end n = n+segMem1(k); end
Any help would be greatly appreciated.
Best Answer