operations on two different matrices

조회 수: 1 (최근 30일)
Mohamed Hajjaj
Mohamed Hajjaj 2021년 9월 14일
댓글: Mohamed Hajjaj 2021년 9월 16일
I need to replace the first row from a matrix A(m.m) by first row from another matrix B(n.n) with different size?

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 16일
D0 j=1,8
A(1, j)=D(2,j+1)
end do
Acol = size(A,2);
A(1,:) = D(2,2:Acol+1);
vec = DD1(1,:);
A1(idx,:) = repmat(vec,numel(idx),1);
Acol = size(A,2);
vec = DD1(1,1:Acol);
A1(idx,:) = repmat(vec, numel(idx), 1);
  댓글 수: 1
Mohamed Hajjaj
Mohamed Hajjaj 2021년 9월 16일
Yes, it works. Thank you very much for your help.

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

추가 답변 (1개)

the cyclist
the cyclist 2021년 9월 14일
편집: the cyclist 2021년 9월 15일
Suppose ...
m = 3;
n = 4;
A = magic(m)
A = 3×3
8 1 6 3 5 7 4 9 2
B = magic(n)
B = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
The first row of A is a 1x3 row vector, and the first row of B is a 1x4 row vector. What do you want the output to be? Also, what if m had been greater than n?
  댓글 수: 6
the cyclist
the cyclist 2021년 9월 15일
Sorry, but your last two comments are just confusing to me.
You did not respond to my questions. What are the results for Case 1, Case 2, etc?
I don't know Fortran anymore, so cannot interpret that.
Why are you suddenly introducing new variables (D, DD1, idx)? Your original question seemed very simple, about filling in the first row of a matrix A, from the first row of a matrix B. It seems to be getting more and more complicated with every comment.
Mohamed Hajjaj
Mohamed Hajjaj 2021년 9월 16일
The first case is the nearest one to my problem.The symbols D, DD1, ...are matrices, but I'm sorry about any confusion. Would you please help me for the first case?

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

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by