how to segment a matrix based on the output in another matrix?

2 Ansichten (letzte 30 Tage)
RAJKUMAR Palaniappan
RAJKUMAR Palaniappan am 7 Jul. 2014
Bearbeitet: Andrei Bobrov am 8 Jul. 2014
Hello everyone,
I request someone to help me in a segmentation problem that i have
i have two matrix A and B, A=[10 20 30 40 50 60 70 80 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800] and B= [1 1 2 2 3 1 2 3], Where A matrix is the original matrix which was segmented to 10 samples per frame (so in this case 8 frames), and the output of these frames are in matrix B. now i want to segment the original matrix (A) by using the B matrix and save it in C matrix. While segmenting the original matrix i want to remove the samples of output 3. For example C= [10 20 30 40 50 60 70 80 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400], C1= [510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700] and so on.
Thanks in advance
With regards
Rajkumar
  2 Kommentare
RAJKUMAR Palaniappan
RAJKUMAR Palaniappan am 7 Jul. 2014
I did the below mentioned code but that does not work
clc clear all close all A=[0 10 20 30 40 50 60 70 80 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800]; A1=buffer(A,10); B= [1 1 2 2 3 1 2 3]'; A1(1:10,1) for i=1:8 if B(i,1)==1 C=A1(1:10,i) elseif B(i,1)==2 C1=A1(1:10,i) else B(i,1)==3 C2=A1(1:10,i) end end
RAJKUMAR Palaniappan
RAJKUMAR Palaniappan am 7 Jul. 2014
Bearbeitet: Star Strider am 7 Jul. 2014
The code below works but it does not segment as i wish. it just takes all the outputs of 1 and saves it in D1 and 2 in D2 and 3 in D3. but i want to segment the first instance of output 1 and 2 and save it together in D1 and then the second instance of 1 and 2 and save it in D2 and so on.
clc
clear all
close all
D1=[];
D2=[];
D3=[];
A=[0 10 20 30 40 50 60 70 80 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800];
A1=buffer(A,10);
B= [1 1 2 2 3 1 2 3]';
A1(1:10,1)
for i=1:8
if B(i,1)==1
C=A1(1:10,i)
D1=[D1;C];
elseif B(i,1)==2
C1=A1(1:10,i)
D2=[D2;C1];
else B(i,1)==3
C2=A1(1:10,i)
D3=[D3;C2];
end
end

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 7 Jul. 2014
Bearbeitet: Andrei Bobrov am 8 Jul. 2014
A1 = reshape(A,10,[]);
C = A1(:,B);
D = C(:);
EDIT
ii = ones(10,1)*B(:).';
D = accumarray(ii(:),A(:),[],@(x){x});

Community Treasure Hunt

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

Start Hunting!

Translated by