Question on sorting and appending data

8 ビュー (過去 30 日間)
Lena Heffern
Lena Heffern 2011 年 7 月 26 日
I'm trying to get the data to sort first by column, 1-360, then by row, 1-74. After it sorts each column, it should return a boolean ring (0's and 1's) ONLY for each row. These rings needs to append onto an image, so for this data set, I should get a maximum of 2 on the image. However, the ring keeps double/triple counting, so I'm getting up to a 5 maximum on the image. After each row, I want to add that row to an image matrix.
My code:
ring=zeros((360),(180));image=zeros((360),(180));
height=floor(100*(rand(74,360)));
width=floor(100*(rand(2,360)));
for m = 1:length(phi)
for n = 1:360
if height(m,n) >= 0 && height(m,n) < 180 && width(m,n) >= 0 && width(m,n) < 360
ring(width(m,n),height(m,n)) = 1;
for i = (1:360)
for j = (1:180)
image(i,j)=image(i,j)+ring(i,j);
end
end
end
end
end
Not sure how else to describe what I'm trying to do, but if there are any question please ask. Thanks!
  2 件のコメント
Doug Hull
Doug Hull 2011 年 7 月 26 日
Huh?
Please give a very small input and expected output. The smallest data set that shows what you are trying to accomplish.
Lena Heffern
Lena Heffern 2011 年 7 月 26 日
What I'm getting:
0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0
0 0 0 0 5 4 0 0
0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 1
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
what I want:
0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0
0 0 0 0 2 2 0 0
0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 1
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Its intersecting data, but on the single rows it sometimes double counts. Its confusing to explain, I know.

サインインしてコメントする。

回答 (1 件)

Lena Heffern
Lena Heffern 2011 年 7 月 26 日
Nevermind, it just needed rearranging and a reset on the ring.
ring=zeros((360),(180));image=zeros((360),(180));
operand=atan(ellipseY./(sqrt(ellipseX.^2 + ellipseZ.^2)));
height=floor(operand * deg + 0.5) + 91;
n=1; m=1;s=0;g=1;
for m = 1:length(phi)
for n = 1:360
if height(m,n) >= 0 && height(m,n) < 180 && width(m,n) >= 0 && width(m,n) < 360
ring(width(m,n),height(m,n)) = 1;
end
end
for i = (1:360)
for j = (1:180)
image(i,j)=image(i,j)+ring(i,j);
end
end
ring=zeros((360),(180));
end

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by