필터 지우기
필터 지우기

give matrix element in for loop

조회 수: 1 (최근 30일)
HADIMARGO
HADIMARGO 2021년 6월 21일
답변: Jan 2021년 6월 21일
hi. i want to make this kind of code in matlab:
a = [ 1 2 3 ];
b1 = 1;
b2 = 3;
b3 = 8;
for i=1:1:3
a(1,i) = b(i)
end
result ==> a = [1 3 8];
how can i create this kind of code in matlab?
pls pay attention i just want to give b1,b2,b3 to a matrix just with "for" loop.

답변 (1개)

Jan
Jan 2021년 6월 21일
Welcome to Matlab.
This is the most frequently asked question and a severe mistake of beginners. Do not hide indices in the names of variables. This is a shot in your knee and demands for ugly methods to access the variables later on. See this excellent tutorial:
The trivial solution is: Do not create b1, b2, b3, ... but store them in a vector from the beginning.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by