Hello all I'm student I'll be glad to help me to solve below problem, that I've two matrices A is 2x9 and B is 6x3,
A= zeros(2,9)
A =
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
B=round(10*rand(6,3))
B =
7 6 9
6 7 8
4 1 7
1 1 1
8 5 1
3 5 1
by using these codes I want to add first three row of matrix B to first row of A and second three rows of matrix B to second row of matrix A by using these codes :::
for i=1:6
if i<=3
x=x(y,:)
else
end
end
I tried I don't know how inside if condition

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 26일

1 개 추천

A= zeros(2,9);
B = [7 6 9
6 7 8
4 1 7
1 1 1
8 5 1
3 5 1];
out = reshape(B',fliplr(size(A)))'

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 26일

1 개 추천

A= zeros(2,9)
B=round(10*rand(6,3))
d=B'
out=[A reshape(d(:),9,[])']

댓글 수: 3

hewaa mero
hewaa mero 2013년 9월 26일
but is will give some zero coloms before adding in the new matrix
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 26일
You said add not replace
hewaa mero
hewaa mero 2013년 9월 26일
your right i mean replace thanks for your feedback

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

dpb
dpb 2013년 9월 26일
편집: dpb 2013년 9월 26일

1 개 추천

Don't need any if (if I understand your request, anyway)...
>> A = reshape(B',9,[])';
A =
7 6 9 6 7 8 4 1 7
1 1 1 8 5 1 3 5 1
>>
ADDENDUM:
Which is the same as Andrei's identically if one doesn't recognize the "9,[]" as equivalent to fliplr(size(A))

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 9월 26일

편집:

dpb
2013년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by