Filter löschen
Filter löschen

For-Loop Algorithm

1 Ansicht (letzte 30 Tage)
RDG
RDG am 2 Dez. 2011
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?

Akzeptierte Antwort

Chandra Kurniawan
Chandra Kurniawan am 2 Dez. 2011
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]

Weitere Antworten (1)

Jan
Jan am 2 Dez. 2011
Hint: mod(1:10, 3)
I assume, this is a homework and do not post the full solution.
  1 Kommentar
RDG
RDG am 2 Dez. 2011
I'll try. Thanks for the hint.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by