Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Need to print Matrix Spiral of an image

1 vue (au cours des 30 derniers jours)
Nimit Jain
Nimit Jain le 6 Juil 2016
Clôturé : John D'Errico le 6 Juil 2016
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 commentaires
Nimit Jain
Nimit Jain le 6 Juil 2016
Means?
John D'Errico
John D'Errico le 6 Juil 2016
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.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by