plot of differernt regions in a matrix

1 Ansicht (letzte 30 Tage)
Hassan
Hassan am 21 Jun. 2011
I have 2 matrixes with the same dimension(100,200). the structure of one the matrixes is something like as follows: class1{row=1:3 and j=4:7>>value=2} class2{row=1:3 and j=8:8>>value=3} class3{row=10:12 and j=150:160>>value=2} class4{row=80:90 and j=150:160>>value=3}
I want to make a plot of pixels in matrix2 which have a value 2 in matrix1 but show them as differnt classes. class 1 has 12 values and class 3 has 33 values. i want a plot which on X axis from 1 to 12 is shown as class 1 and from 13 to 13+33 as class3. I'm not sure if I asked my question clearly, but please let me know if it's not clear. I appereciate your help.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 21 Jun. 2011
m1 = rand(100,200);
m2 = zeros(size(m1));
m2(1:3,4:7)=2;
m2(10:12,150:160)=2;
m2(1:3,8)=3;
m2(80:90,150:160)=3;
L = bwlabel(m2 == 2);
[r c v] = find(L);
wmtx = sortrows([r c v],3);
plot(1:size(wmtx,1),m1(sub2ind(size(m1),wmtx(:,1),wmtx(:,2))));
ADD on comment
pm1 = m1(sub2ind(size(m1),wmtx(:,1),wmtx(:,2)));
dplt = mat2cell([(1:size(wmtx,1))' pm1],...
arrayfun(@(i1)nnz(wmtx(:,3)==i1),1:max(wmtx(:,3))) ,ones(1,2));
plot(dplt{1,:},'r*-',dplt{2,:},'go-')
corrected 'plot(...'
n = size(wmtx,1);
k=reshape('ymcrgbwk+o*.xv^>--------',[],3);
dplt2 = [dplt mat2cell([repmat(k,fix(n/8),1);k(1:rem(n,8),:)],ones(n,1),3)]';
plot(dplt2{:})
COD of last correcting
L = bwlabel(m2 == 2);
[r c v] = find(L);
wmtx = sortrows([r c v],3);
pm1 = m1(sub2ind(size(m1),wmtx(:,1),wmtx(:,2)));
dplt = mat2cell([(1:size(wmtx,1))' pm1],...
arrayfun(@(i1)nnz(wmtx(:,3)==i1),1:max(wmtx(:,3))) ,ones(1,2));
n = size(dplt,1);
k=reshape('ymcrgbwk+o*.xv^>--------',[],3);
dplt2 = [dplt mat2cell([repmat(k,fix(n/8),1);k(1:rem(n,8),:)],ones(n,1),3)]';
plot(dplt2{:})
  10 Kommentare
Andrei Bobrov
Andrei Bobrov am 22 Jun. 2011
Sorry! It's my typo! Correcting in 'k = [...'
Hassan
Hassan am 23 Jun. 2011
thanks a lot Andrei.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by