필터 지우기
필터 지우기

For-Loop Algorithm

조회 수: 1 (최근 30일)
RDG
RDG 2011년 12월 2일
Can anybody help me with this?
A = cell(10,1) %Cell Array with 10 Rows and 1 Column
B is another cell array with contents as such:- B = [1][2][3]
I wish to insert the content of B into A in such manner using for-loop: A = [1][2][3][1][2][3][1][2][3][1]
How do I achieve such result with for loop?

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 2일
clear; clc;
A = cell(10,1);
B = num2cell([1 2 3]);
for x = 1 : numel(A)
idk = mod(x,3);
if idk == 0
idk = 3;
end
A{x} = B{idk};
end
The result :
>> A
A =
[1]
[2]
[3]
[1]
[2]
[3]
[1]
[2]
[3]
[1]
  댓글 수: 1
RDG
RDG 2011년 12월 2일
Thanks!

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

추가 답변 (1개)

Jan
Jan 2011년 12월 2일
Hint: mod(1:10, 3)
I assume, this is a homework and do not post the full solution.
  댓글 수: 1
RDG
RDG 2011년 12월 2일
I'll try. Thanks for the hint.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by