이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.
채택된 답변
Andrei Bobrov
2011년 6월 21일
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
Hassan
2011년 6월 21일
thanks a lot Andrei. It's the one I need. The only missing thing which is also important for me is if I can show differernt regions with differernt color in the plot. for example if the whole range of values on X-axis is 1 to 45 and say 1 to 5 is the first connected values and 6 to 20 is the second one, I can show each of them with a seperate color.
Hassan
2011년 6월 21일
the add on code works for the example u used but it not working for my data. I have more than 200 regions with value 2 in differernt part of image.
Andrei Bobrov
2011년 6월 21일
Present the data (small part) to which the code is not working
Hassan
2011년 6월 21일
I'd like to but I dont know how to present the data. I dont think I can import the data here, can I?
Hassan
2011년 6월 21일
in dplt variable i have 323*2cell.
Andrei Bobrov
2011년 6월 21일
create three matrixs: 1. m1; 2. value; 3. class;
Hassan
2011년 6월 22일
Sorry but I dont understand it.
Hassan
2011년 6월 22일
I got the following error:
??? Error using ==> horzcat
CAT arguments dimensions are not
consistent.
Andrei Bobrov
2011년 6월 22일
Sorry! It's my typo! Correcting in 'k = [...'
Hassan
2011년 6월 23일
thanks a lot Andrei.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
