フィルターのクリア

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