How to index in for loop

조회 수: 1 (최근 30일)
rakesh kumar
rakesh kumar 2021년 4월 2일
댓글: rakesh kumar 2021년 4월 2일
I have a an array
a=[4 9 7]
A Matrix
b= [5 7;4 2];
I want to have
c1=4*b c2=9*b; c3=7*b
. I want to use c1,c2"c3' later as d1=r-c1*x; d2=r-c2*x; Where r=[4;9]; x=[3 5]

채택된 답변

David Hill
David Hill 2021년 4월 2일
편집: David Hill 2021년 4월 2일
for k=1:length(a)
c(:,:,k)=a(k)*b;%index instead of having different variables
d(:,:,k)=r-c(:,:,k)*x;
end
  댓글 수: 1
rakesh kumar
rakesh kumar 2021년 4월 2일
Thanks david, thanks a lot

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

추가 답변 (0개)

카테고리

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