select a band of a matrix

1 次查看(过去 30 天)
Hello I want to select a band of a matrix with slop (S) and save them in another matrix.
a =
[ 1 2 3 4 5 6 7 8 9;
11 12 13 14 15 16 17 18 19;
21 22 23 24 25 26 27 28 29;
31 32 33 34 35 36 37 38 39;
41 42 43 44 45 46 47 48 49;
51 52 53 54 55 56 57 58 59]
Foe example I have a slope S1, and I want to select a band of this matrix in this way: Assume we can draw a line from array "6" to "29" and another line from "21" to "55". and remove the arrays above line 1 and below line 2. My problem is something like this but a little different. I have 2 slopes that I want to cut my matrix according with. Can you please help me to write a code for this problem?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-28
[ii,jj]= ndgrid(1:size(a,1),1:size(a,2));
[I J] = find(ismember(a,[21;55;6;29]));
out = a.*(ii - I(1) > (diff(I(1:2)))/(diff(J(1:2)))*jj | ii - I(end) + 1< (diff(I(3:end)))/(diff(J(3:end)))*(jj - J(end)+1));

更多回答(1 个)

Image Analyst
Image Analyst 2012-5-28
I don't know what you're trying to explain. I can get the elements fo the array going from 6 to 29 and from 21 to 55 this way:
a =...
[ 1 2 3 4 5 6 7 8 9;
11 12 13 14 15 16 17 18 19;
21 22 23 24 25 26 27 28 29;
31 32 33 34 35 36 37 38 39;
41 42 43 44 45 46 47 48 49;
51 52 53 54 55 56 57 58 59]
aLinear = a'
aLinear = aLinear(:)
a_6_29 = aLinear(6:27)
a_21_55 = aLinear(21:50)
% Now what? I have no idea.
But I don't know what to do after that. Do you want to get a slope of a line fitted through those vectors? What does this mean: "remove the arrays above line 1 and below line 2."? To me that means you want line (row) 2 and nothing else, like this:
% Remove the arrays above line 1 and below line 2.
% That would leave only line 2 itself remaining.
a_new = a(2, :);
  2 个评论
Andrea
Andrea 2012-5-28
please see these images. That can help me to explain the problem better.
image 1: http://imageshack.us/photo/my-images/268/64770753.jpg/
image 2: http://imageshack.us/photo/my-images/405/52265040.jpg/
The fact is (as I explained weekly before) , I have two image matrix with both x and y of them. These two images has been taken with two different instruments (Satellite radar and ground radar) and have different spatial resolutions. I want to do somethings that really needs to have two image with exactly same geometric area. I don't want to define some specific points and change the image 1 according to image 2 because I have lots of other image from these two instruments. So I cannot define the intersection area (overlapping area) of each two images separately which may takes a lot of time. I want to write a program in Matlab which cut image 1 in the way it only has the data the image 2 already has. You can see that image 1 data has been defined in a band ( the blue band ) while image 1 has a circle form of data. I want to cut image 2 to have only this band area as image 1. I hope I explained the problem a little clearly than before.
Andrea
Andrea 2012-5-28
we can draw a line from array "6" to "29" and another line from "21" to "55". I want to remove arrays at the triangle made by the line 1 (from "6" to "29" a) and the the other triangle made at the left bottom corner of the matrix (from "6" to "29" ).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by