필터 지우기
필터 지우기

Copy element of matrix to another matrix

조회 수: 16 (최근 30일)
baby
baby 2013년 1월 21일
답변: Annmaria T Joy 2020년 5월 7일
hello all,,
i wanna ask about how to copy element of matrix to another matrix
example :
i've matrix B and i want the element of matrix B copied into another matrix(matrix F)
this's my code
a= input ('Input Number of Data :');
for c=1:a
int2 = ['Input The First Score - ',num2str(c),' :'];
int3 = ['Input The Second Score - ',num2str(c),' :'];
str = ['Input Category ke - ',num2str(c),' :'];
b(c,1) = input(int2);
b(c,2) = input(int3);
f{c,3} = input(str,'s');
end;
everytime i use command "f=b(:,1:2)" the element of matrix f is missing and that's change with element of matrix b
i want the element of matrix f still in matrix f although the element of matrix b copied into matrix f
please help me
NB : sorry for my bad english :)

채택된 답변

Thorsten
Thorsten 2013년 1월 21일
If you want to copy for each c the first two elemens of b to f, use inside the for loop
f(c, 1:2) = b(c, 1:2);
Or you can also do this for all rows outside the for loop using
f(:, 1:2) = b(:, 1:2);
  댓글 수: 3
Thorsten
Thorsten 2013년 1월 21일
You can do it like this
for i = 1:size(b,1)
for j = 1:2
f{i,j} = b(i,j);
end;
end
I tried f{: 1:2} = num2cell(b(:, 1:2)) but that did not work.
baby
baby 2013년 1월 21일
thx u so much Thorsten :)

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

추가 답변 (1개)

Annmaria T Joy
Annmaria T Joy 2020년 5월 7일
How to copy the output from a loop to a matrix?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by