Hi every one briefly, I have i=3:5 and j=1:3 and My equation is how to let i=3 for calculating the first raw and let j changes from 1:3 and for second raw i =4 and let j changes from 1:3 and third raw i =4 and let j changes from 1:3 and third
% Calculate the first row.
i=3
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end
% Calculate the second row
i=4
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end
% Calculate the third row
i=5
for j=1:3
A(i,j)=(A(i-1,1)*A(i-2,j+1)-A(i-1,j+1)*A(i-2,1))/(A(i-1,1))
end

 채택된 답변

Image Analyst
Image Analyst 2014년 7월 5일

0 개 추천

Try this:
clc; % Clear command window.
A = magic(5); % Create some sample data.
% Calculate the first row.
for row = 3 : 5
for column = 1 : 3
A(row, column)= ...
(A(row-1, 1) * A(row-2, column+1) - ...
A(row-1, column+1) * A(row-2, 1)) / ...
A(row-1, 1);
end
end
A % Print to command window.

댓글 수: 2

Matlab & Simulink
Matlab & Simulink 2014년 7월 5일
Thank you very much Image Analyst
Image Analyst
Image Analyst 2014년 7월 5일
If you want to tall me what you want to do, there may be a vectorized way, or a function to do what you want to do.

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

추가 답변 (1개)

ES
ES 2014년 7월 5일

0 개 추천

for i=3:5
for j=1:3
%calculations here.
end
end
Two suggestions: 1. Dont use i and j as variables in matlab as they denote sqrt(-1) 2. Pre allocate arrays before calculation for speed

댓글 수: 1

Matlab & Simulink
Matlab & Simulink 2014년 7월 5일
thanks for replaying
it doesn't work, because I want i=3 for all the first row and j=1:3 and for the second row i = 4 and j=1:3 and so on

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

카테고리

도움말 센터File 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