필터 지우기
필터 지우기

How can I write this C code snippet in MATLAB?

조회 수: 1 (최근 30일)
Febin Benjamin
Febin Benjamin 2014년 1월 5일
답변: Adithya 2023년 2월 28일
for(j=0;j<n;j++)
{
for(i=0,k=j;i<=j && k<=j; i++)
{
printf("%d ", Mat[k][i]);
k--;
}
}
The difference in for loop syntax between the two languages is troubling me actually... Please help
  댓글 수: 2
James Tursa
James Tursa 2014년 1월 5일
What is the line "print [k][i]" supposed to do?
Febin Benjamin
Febin Benjamin 2014년 1월 5일
편집: Febin Benjamin 2014년 1월 5일
it will print the value present at the point [k][i] of a 2-D matrix

댓글을 달려면 로그인하십시오.

답변 (1개)

Adithya
Adithya 2023년 2월 28일
In the above code you are trying to print elements in anti diagonal fashion for example :
Consider Mat = [1,2,3;4,5,6;7,8,9]
Now u have to print it as
1
4 2
7 5 3
% Define the matrix
m = [1 2 3; 4 5 6; 7 8 9];
% Get the number of rows in the matrix
n = size(m, 1);
% Loop over the rows of the matrix and print them in the desired format
cnt=0;
for j = 1:3
k=1;
for i=1:j
disp(m(j-i+1,k))
k=k+1;
end
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by