필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Need to print Matrix Spiral of an image

조회 수: 1 (최근 30일)
Nimit Jain
Nimit Jain 2016년 7월 6일
마감: John D'Errico 2016년 7월 6일
Hello, I have written a program in Java to spiral print of 2-dimensional array. Now need that in matlab. My image size is (768, 738, 3)
package ArrayAndString;
public class MatrixSpiral {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] a = {{1,2,3,4,5,6},
{7,8,9,10,11,12},
{13,14,15,16,17,18}};
System.out.println(a.length+" "+a[0].length);
int row = a.length;
int col = a[0].length;
spiralPath(row, col, a);
}
private static void spiralPath(int m, int n, int[][] a) {
int i, k = 0, l = 0;
/* k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator
*/
while(k<m && l<n)
{
// Print the first row from the remaining rows
for(i=l; i<n;++i)
{
System.out.print(a[k][i]+" ");
}
k++;
/* Print the last column from the remaining columns */
for(i = k;i<m;++i)
{
System.out.print(a[i][n-1]+" ");
}
n--;
/* Print the last row from the remaining rows */
if(k<m)
{
for(i=n-1;i >= l ;--i)
{
System.out.print(a[m-1][i]+" ");
}
m--;
}
/* Print the first column fromthe remaining columns */
if(l<m)
{
for(i = m-1; i>= k; --i)
{
System.out.print(a[i][l]+" ");
}
l++;
}
}
}
}
  댓글 수: 3
Nimit Jain
Nimit Jain 2016년 7월 6일
Means?
John D'Errico
John D'Errico 2016년 7월 6일
It means that we don't write your code for you here. You need to make an effort. After all, this is your homework, not ours.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by