필터 지우기
필터 지우기

I have a question about for loop

조회 수: 1 (최근 30일)
Sudharsan Srinivasan
Sudharsan Srinivasan 2017년 7월 17일
댓글: Sudharsan Srinivasan 2017년 7월 17일
Lets say a = [1,2,3....35] and b = [1,2,3...35]. The size of both the vectors are same i.e. 1 by 35. I have another matrix say R = [1 2 ; 3 4] whose size is 2 by 2. I wanted to do matrix multiplication as follows, c = R * [a(i);b(j)], where i and j are the total length of the vectors a and b respectively. I wanted to print the value of c (whose size is 1 by 2) for example c(1) = R * (a(1);b(1)) and c(2) = R * (a(2);b(2)) etc., till c(35). Each time i get the value of c, I have to compute x and y as follows,
[x;y] = [e;f] + c. Here e and f is again a 1 by 2 vector.
Finally I should have a 1 by 35 vector for x and y each.
How can I code this ?

답변 (1개)

Jan
Jan 2017년 7월 17일
편집: Jan 2017년 7월 17일
What about:
xy = [e;f] + R * [a;b] % >= Matlab R2016b
? With older versions:
xy = bsxfun(@plus, [e;f], R * [a;b])
Now x is the first row, y the second one.
  댓글 수: 1
Sudharsan Srinivasan
Sudharsan Srinivasan 2017년 7월 17일
Hello Mr. Jan Simon,
Thank you for your answer. I in fact did the same thing what you have mentioned. I was wondering if I can print x and y separately instead of defining a single variable xy.
Thanks a million for your time.
Sudharsan.

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

카테고리

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