필터 지우기
필터 지우기

.append() equivalent in MATLAB

조회 수: 1,538 (최근 30일)
Swati Sarangi
Swati Sarangi 2020년 11월 9일
답변: Amir Azadeh Ranjbar 2023년 10월 6일
Hi all,
I have a doubt regarding the function in MATLAB which will perform same function as performed by .append() in PYTHON. Do you have any function in mind which will use same activity of extending a list in MATLAB.
Thanks in advance!

채택된 답변

Stephan
Stephan 2020년 11월 9일
>> List = [1 2 3; 4 5 6]
List =
1 2 3
4 5 6
>> List = [List; 7 8 9]
List =
1 2 3
4 5 6
7 8 9
  댓글 수: 3
Saunok Chakrabarty
Saunok Chakrabarty 2021년 4월 22일
Hi Stephan,
Is there a function that expands an array dynamically inside a loop, like append() in Python? Like it will keep adding elements based on a specified condition within the loop.
Regards,
Saunok
Cem Keske
Cem Keske 2021년 10월 19일
Hello,
You can use this directly to expand the array dynamically:
array = [array, other_array];
For example:
array = [];
for i = 1:10
if mod(i,2) == 0
array = [array, i]
end
end
array = 2
array = 1×2
2 4
array = 1×3
2 4 6
array = 1×4
2 4 6 8
array = 1×5
2 4 6 8 10
I hope this helps,
Regards,
Cem

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

추가 답변 (1개)

Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2023년 10월 6일
yes...
you can use end :
there are many way to do this :
examples :
ThemeCopy
x = [1,2,3,4,5] ;
y = [6,7,8] ;
Num_Add = size(y,2) ;
counter = 1 ;
while counter <= Num_Add
Last = size(x,2)+1 ;
x(1,Last) = y(1,counter) ;
counter = counter + 1;
end
disp(x)
1 2 3 4 5 6 7 8
also you can python in matlab very easy :
ThemeCopy
data = py.list([1,2,3,4]) ;
data.append(9)
double(data)
ans = 1×5
1 2 3 4 9
Another example that can be used to add rows to the table
ThemeCopy
data_mat = [1;2;3;4] ;
data = table(data_mat) ;
new_data = {5} ;
data = [data;new_data]

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by