필터 지우기
필터 지우기

How to create a new matrix with a for loop?

조회 수: 1 (최근 30일)
Mert Dogan
Mert Dogan 2021년 9월 15일
댓글: Mert Dogan 2021년 9월 15일
Hello friends,
I am a newbie. I have problem.
I have 20 (1x100) different named vectors. I want to combine these vectors to create a 20x100 matrix with a for loop.
There are the examples of vectors.
namelist=["First","B","New"]
namelist = 1×3 string array
"First" "B" "New"
First = [1:100]
First = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
B = [1:2:200]
B = 1×100
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59
New = [4:4:400]
New = 1×100
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120
I want to create a new database(20x100) with "First, B , New" vectors with a for loop.
for i = 1: length(namelist)
new_database(i,1:end) = namelist{i}
end
The end operator must be used within an array index expression.
But, when I want to try this I saw "The end operator must be used within an array index expression." error.
I know I can do same thing with this code
new_database= [First;B;New]
but i want to do this with a for loop.
Would you help me how can fix this error? or Would you explain me how can do this?

채택된 답변

KSSV
KSSV 2021년 9월 15일
You should not create individual arrays like that. You should proceed something like this
iwant = zeros(3,100) ;
iwant(i,:) = 1:1:100 ;
iwant(2,:) = 2:2:200 ;
iwant(3,:) = 4:4:400 ;
  댓글 수: 1
Mert Dogan
Mert Dogan 2021년 9월 15일
Thanks for your answer.
I had already created individual arrays like that. I must to process them.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by